transform itemgroup into another itemgroup with wildcards
I have a list of directories defined inside a target:
<Target>
<ItemGroup>
<FooDirs Include="Foo\Dir1" />
<FooDirs Include="Foo\Dir2" />
</ItemGroup>
<Target>
Now I want to create list of all files inside @(FooDirs)
:
<ItemGroup>
<FooFiles Include="@(FooDirs -> '%(Identity)\**\*')" />
</ItemGroup>
Which unfortunat开发者_Python百科ely does not work, resulting list contains literal strings: "Foo\Dir1\**\*;Foo\Dir2\**\*"
.
However, if I use deprecated <CreateItem>
task it works fine:
<CreateItem Include="@(FooDirs -> '%(Identity)\**\*')">
<Output TaskParameter="Include" ItemName="FooFiles" />
</CreateItem>
Is this a bug or am I missing something ?
Try this instead, it will properly create FooFiles using task batching:
<Target Name="Foo">
<ItemGroup>
<FooDirs Include="Foo\Dir1" />
<FooDirs Include="Foo\Dir2" />
</ItemGroup>
<ItemGroup>
<FooFiles Include="%(FooDirs.Identity)\**\*" />
</ItemGroup>
<Message Text="%(FooFiles.Identity)" />
</Target>
(Excerpted from the book "MSBuild Trickery" trick #5)
精彩评论