条件默认项元数据

时间:2013-06-11 10:07:49

标签: msbuild

我希望 Content\**下的所有项目文件默认设置为CopyToOutputDirectory,同时仍然需要添加每个项目(因此没有通配符包括)。类似的东西:

PreserveNewest

不幸的是,ItemDefinition不支持<ItemDefinitionGroup> <Content Include="Content\**\*"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> </ItemDefinitionGroup> 属性。 我也尝试过:

Include

建议here,但似乎它在ItemDefinition中不起作用。 事实上,当我尝试这个时:

<ItemDefinitionGroup>
  <Content>
    <CopyToOutputDirectory Condition="$([System.String]::new('%(Identity)').StartsWith('Content\'))">PreserveNewest</CopyToOutputDirectory>
  </Content>
</ItemDefinitionGroup>

“属性”窗格报告的CustomToolNamespace的值为<ItemDefinitionGroup> <Content> <CustomToolNamespace>Foo = $([System.String]::new(%(Identity)))</CustomToolNamespace> </Content> </ItemDefinitionGroup>

1 个答案:

答案 0 :(得分:0)

如果要为项目组创建新的元数据:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
<ItemDefinitionGroup>
    <Content>
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
</ItemDefinitionGroup>

<Target Name="Definition">
   <ItemGroup>
      <Content Include="Content\**\*"/>
   </ItemGroup>

   <Message Text="%(Content.CopyToOutputDirectory)"/>
</Target>
</Project>

这会将新的元数据添加到项目组。

您还可以根据不同的包含和元数据组合两个项目组,例如:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
<ItemDefinitionGroup>
    <WithContent>
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </WithContent>
</ItemDefinitionGroup>

<Target Name="Definition">
   <ItemGroup>
      <NotContent Include="Content\**\not*"/>
   </ItemGroup>
   <ItemGroup>
      <WithContent Include="Content\**\with*"/>
   </ItemGroup>

   <ItemGroup>
     <Content Include="@(NotContent)"/>
     <Content  Include="@(WithContent)"/>
   </ItemGroup>

   <Message Text="Added together: %(Content.CopyToOutputDirectory)"/>
   <Message Text="Added together: %(Content.Identity)"/>

</Target>
</Project>