I am attempting to write a build script for our source tree. This tree consists of a (large) number of solutions with assembly references between them. I have created an I
Ah. Stumbled on an answer whilst playing around with this.
Firstly, I was investigating this post about getting the intersection of two item groups. I therefore changed my OutputNames item group to have the same Identity as the OutputProjects ItemGroup:
<OutputNames Include="$(MSBuildProjectDirectory)\Solution1\Project1A\Project1A.csproj">
<OutputFolder>ArbitraryFolder1</OutputFolder>
</OutputNames>
<OutputNames Include="$(MSBuildProjectDirectory)\Solution2\Project2B\Project2B.csproj">
<OutputFolder>ArbitraryFolder2</OutputFolder>
</OutputNames>
This let me batch on %(Identity) and get the intersection like this:
<Message Condition="'%(Identity)' != '' and
'@(OutputProjects)' != '' and
'@(OutputNames)' != ''"
Text="Found a match for %(Identity)" />
However, when also referring to the OutputFolder metadata in the same Task, that became part of the batching as well resulting in the following never printing to the output:
<Message Condition="'%(Identity)' != '' and
'@(OutputProjects)' != '' and
'@(OutputNames)' != ''"
Text="Found a match for %(Identity): %(OutputNames.OutputFolder)" />
But, by using a transform over the property instead of direct access, it isn't treated as part of the batching:
<Message Condition="'%(Identity)' != '' and
'@(OutputProjects)' != '' and
'@(OutputNames)' != ''"
Text="Found a match for %(Identity): @(OutputNames->'%(OutputFolder)')" />
Therefore, I can do the following to update my metadata:
<!-- Now override specific projects OutputTo metadata -->
<OutputProjects Condition="'%(Identity)' != '' AND
'@(OutputProjects)' != '' AND
'@(OutputNames)' != ''">
<OutputTo>@(OutputNames->'%(OutputFolder)')</OutputTo>
</OutputProjects>