使用通配符将项目组转换为另一个项目组 [英] transform itemgroup into another itemgroup with wildcards

查看:62
本文介绍了使用通配符将项目组转换为另一个项目组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在目标内定义了一个目录列表:

I have a list of directories defined inside a target:

<Target>
  <ItemGroup>
    <FooDirs Include="Foo\Dir1" />
    <FooDirs Include="Foo\Dir2" />
  </ItemGroup>
<Target>

现在我要创建@(FooDirs)中所有文件的列表:

Now I want to create list of all files inside @(FooDirs):

<ItemGroup>
  <FooFiles Include="@(FooDirs -> '%(Identity)\**\*')" />
</ItemGroup>

不幸的是,这不起作用,结果列表包含文字字符串:"Foo\Dir1\**\*;Foo\Dir2\**\*". 但是,如果我使用了不推荐使用的<CreateItem>任务,则可以正常工作:

Which unfortunately 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 ?

推荐答案

试试看,它将使用任务批处理正确创建FooFiles:

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> 

(摘自《 MSBuild Trickery》技巧#5)

(Excerpted from the book "MSBuild Trickery" trick #5)

这篇关于使用通配符将项目组转换为另一个项目组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆