001 – Join ItemGroups based on Metadata


Problem Statement

How can two different item groups be joined based on metadata

Solutions

1.

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="Default">
      <ItemGroup>
        <!– Group1 Items –>
        <Group1 Include="Red">
          <IsFavorite>false</IsFavorite>
        </Group1>
        <Group1 Include="Yellow">
          <IsFavorite>true</IsFavorite>
        </Group1>
        <Group1 Include="Green">
          <IsFavorite>true</IsFavorite>
        </Group1>
       
        <!– Group2 Items –>
        <Group2 Include="Blue">
          <IsFavorite>true</IsFavorite>
        </Group2>
        <Group2 Include="Grey">
          <IsFavorite>false</IsFavorite>
        </Group2>
        <Group2 Include="Silver">
          <IsFavorite>true</IsFavorite>
        </Group2>
        <!– Combine the groups where IsFavorite is true –>
        <Group3 Include="@(Group1);@(Group2)" Condition="’%(IsFavorite)’ == ‘true’"/>
      </ItemGroup>
      <!– Display the results –>
      <Message Text="Group 1 – %(Group1.Identity)"/>
      <Message Text="Group 2 – %(Group2.Identity)"/>
      <Message Text="Group 3 – %(Group3.Identity)"/>
    </Target>
</Project>

 

Comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s