开发者

transform itemgroup into another itemgroup with wildcards

开发者 https://www.devze.com 2023-04-01 21:52 出处:网络
I have a list of directories defined inside a target: <Target> <ItemGroup> <FooDirs Include=\"Foo\\Dir1\" />

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消