MSDN > 論壇首頁 > MSBuild > Filter MSBuild items
發問發問
 

已答覆Filter MSBuild items

  • Wednesday, 24 September, 2008 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

     

解答

  • Wednesday, 24 September, 2008 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)


  • Wednesday, 24 September, 2008 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

所有回覆

  • Wednesday, 24 September, 2008 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)


  • Wednesday, 24 September, 2008 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
  • Wednesday, 24 September, 2008 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