Msbuild 条件默认项元数据

Msbuild 条件默认项元数据,msbuild,Msbuild,我希望Content\**下的所有项目文件在默认情况下将CopyToOutputDirectory设置为preservedlatest,同时仍然必须添加每个项目(因此不包含通配符)。比如: <ItemDefinitionGroup> <Content Include="Content\**\*"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </C

我希望
Content\**
下的所有项目文件在默认情况下将
CopyToOutputDirectory
设置为
preservedlatest
,同时仍然必须添加每个项目(因此不包含通配符)。比如:

<ItemDefinitionGroup>
  <Content Include="Content\**\*">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </Content>
</ItemDefinitionGroup>
正如建议的那样,但它似乎在ItemDefinition中不起作用。 事实上,当我尝试这样做时:

<ItemDefinitionGroup>
  <Content>
    <CustomToolNamespace>Foo = $([System.String]::new(%(Identity)))</CustomToolNamespace>
  </Content>
</ItemDefinitionGroup>

Foo=$([System.String]::新建(%(标识)))

“属性”窗格报告的CustomToolNamespace的值为
Foo=%(标识)

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

<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>

保存最新
这会将新的metatdata添加到itemgroup

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

<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>

保存最新

这将在所有内容上设置
CopyToOutputDirectory
,而不仅仅是在'content'中,并将该目录中的所有文件包含到项目中,这是我不希望发生的(“因此没有通配符包含”)。是的,它将对任何名为content的项目组执行此操作。不过,停止使用另一个名称,甚至多个项目组并进行组合是没有什么好处的。我不认为使用另一个名称会有什么帮助。我需要
上的元数据。但我希望避免使用通配符include。我只需要项目文件中的项目的默认值。
<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>