XtianGIS
XtianGIS

Reputation: 1006

MSBuild - ItemGroup intersection

If there is an ItemGroup that includes the file name and the extension, and other ItemGroup that includes just the files names:

<ItemGroup>
        <GroupA Include="file.1.txt"/>
        <GroupA Include="file.2.txt"/>
        <GroupA Include="file.3.txt"/>
        <GroupA Include="file.4.txt"/>
</ItemGroup>


 <ItemGroup>
        <GroupB Include="file.1"/>
        <GroupB Include="file.3"/>
        <GroupB Include="file.5"/>
</ItemGroup>

How to get the items from the GroupA that match the names in the GroupB?

I was checking the information posted here but, it does not apply due the lack of the extensions.

Upvotes: 3

Views: 629

Answers (1)

XtianGIS
XtianGIS

Reputation: 1006

Introducing a temporal ItemGroup which extends the name of the object with a tmp extension, it can be reached:

<CreateItem Include="%(GroupB.Filename)%(GroupB.Extension).tmp" 
    AdditionalMetadata="CompleteName=%(GroupB.Filename)%(GroupB.Extension)">
    <Output TaskParameter="Include" ItemName="GroupB1" />
</CreateItem>

<Message Text="%(GroupB1.CompleteName)"/>
<Message Text="|@(GroupA)| – |%(Filename)| – |@(GroupB1)|"/>

<CreateItem Include="@(GroupA)" Condition="'%(Filename)' != ''and '@(GroupB1)' != ''">
    <Output TaskParameter="Include" ItemName="GroupC"/>
</CreateItem>
<Message Text="%(GroupC.Filename)"/>

Upvotes: 1

Related Questions