• Upgrade your Internet Experience
  • Sign in
  • Microsoft.com
  • United States (English)
    Brasil (Português)Česká republika (Čeština)Deutschland (Deutsch)España (Español)France (Français)Italia (Italiano)Россия (Русский)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語)香港特别行政區 (中文)
 
 
.NET Framework Developer Center
 
 
Home
 
 
Library
 
 
Learn
 
 
Downloads
 
 
Support
 
 
Community
 
 
Forums
 
 
 
.NET Framework Developer Center > .NET Development Forums > MSBuild > Filter MSBuild items
Ask a questionAsk a question
Search Forums:
  • Search MSBuild Forum Search MSBuild Forum
  • Search All .NET Development Forums Search All .NET Development Forums
  • Search All MSDN Forums Search All MSDN Forums
 

AnswerFilter MSBuild items

  • Wednesday, September 24, 2008 8:41 AMJohnDooner Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Vote As Helpful
    0
    Hi Guys,

    Problem:
    I'm trying to filter a item list (GroupA), with item list (GroupB) to generate GroupC. So far I have tried this using batching and Transforms with no luck. 

    Background:
    GroupA is a list been generated from a custom Msbuild task. Its metadata structure cannot be changed. The idea here is to search GroupA for list of filenames contained within GroupB.

    <GroupA Include="ann.exe"/>
    <
    GroupA Include="barry.exe"/>
    <
    GroupA Include="claire.exe"/>
    <
    GroupA Include="dermot.exe"/>

    <GroupB Include="ann.exe"/>
    <
    GroupB Include="barry.exe"/>

    Possible solution:

    <CreateItem Include="@(GroupA)" Condition="'%(GroupA.filename)' == 'ann' or '%(GroupA.filename)' == 'barry'" >
            <
    Output TaskParameter="Include" ItemName="GroupC"/>
    </
    CreateItem>

    Any help on this would be appreciated.

    Thanks
    John

     

    • ReplyReply
    • QuoteQuote
     

Answers

  • Wednesday, September 24, 2008 9:13 AMMike FourieModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Vote As Helpful
    0
    I think the following will work for you

       <FTDMsBuild TaskAction="GetCommonItems" InputItems1="@(GroupA)" InputItems2="@(GroupB)">

            <Output TaskParameter="OutputItems" ItemName="GroupC"/>

        </FTDMsBuild>

    The task is in the FreeToDev MSBuild Tasks Suite, available here: http://www.codeplex.com/freetodevtasks

    That task will do a bunch of other things for you too...

    GetCommonItems (Required: InputItems1, InputItems2 Output: OutputItems, ItemCount)

    GetDistinctItems (Required: InputItems1, InputItems2 Output: OutputItems, ItemCount)

    GetItem (Required: InputItems1, PositionOutput: OutputItems)

    GetLastItem (Required: InputItems1Output: OutputItems)

    GetItemCount (Required: InputItems1 Output: ItemCount)

    GetCurrentDirectory (Output: CurrentDirectory)

    RemoveDuplicateFiles (Required: InputItems1 Output: OutputItems, ItemCount)

    Sort (Required: InputItems1Output: OutputItems)

    StringToItemCol (Required: ItemString, Separator Output: OutputItems, ItemCount)


    • Marked As Answer byFeng ChenMSFT, ModeratorFriday, September 26, 2008 9:22 AM
    •  
    • ReplyReply
    • QuoteQuote
     
  • Wednesday, September 24, 2008 8:53 PMChris Eargle Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Vote As Helpful
    0

    I tried several different ways to make this work. I ended up having to do to two excludes to perform an inner join in MSBuild without outside tasks.

    <CreateItem Include="@(GroupA)" Exclude="@(GroupB)" >
        <
    Output TaskParameter="Include" ItemName="GroupC"/>
    </
    CreateItem>

    <
    CreateItem Include="@(GroupA)" Exclude="@(GroupC)" >
        <
    Output TaskParameter="Include" ItemName="GroupD"/>
    </
    CreateItem>

    <
    Message Text="@(GroupD)"/>

    KodefuGuru.com - Life Student of the Kodefu Arts
    • Marked As Answer byFeng ChenMSFT, ModeratorFriday, September 26, 2008 9:22 AM
    •  
    • ReplyReply
    • QuoteQuote
     

All Replies

  • Wednesday, September 24, 2008 11:15 PMChris Eargle Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    I posted a blog article explaining set operations with item collections in more detail.

    http://www.kodefuguru.com/post/2008/09/Set-Operations-in-MSBuild.aspx
    KodefuGuru.com - Life Student of the Kodefu Arts
    • ReplyReply
    • QuoteQuote
     
Need Help with Forums? (FAQ)
 
© 2009 Microsoft Corporation. All rights reserved.
Terms of Use
|
Trademarks
|
Privacy Statement