提出问题提出问题
 

已答复Filter MSBuild items

  • 2008年9月24日 8:41JohnDooner 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     包含代码
    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

     

答案

  • 2008年9月24日 9:13Mike Fourie版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复包含代码
    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)


  • 2008年9月24日 20:53Chris Eargle 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复包含代码

    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

全部回复

  • 2008年9月24日 9:13Mike Fourie版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复包含代码
    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)


  • 2008年9月24日 20:53Chris Eargle 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复包含代码

    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
  • 2008年9月24日 23:15Chris Eargle 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    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