2

我希望所有项目文件都默认设置为 同时仍然必须添加每个项目(因此没有通配符 include)。就像是:Content\**CopyToOutputDirectoryPreserveNewest

<ItemDefinitionGroup>
  <Content Include="Content\**\*">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </Content>
</ItemDefinitionGroup>

不幸的是 ItemDefinition 不支持Include属性。我也试过:

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

正如这里所建议的,但它似乎在 ItemDefinition 中不起作用。事实上,当我尝试这样做时:

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

属性窗格报告的 CustomToolNamespace 的值为Foo = %(Identity)

4

1 回答 1

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>
于 2013-06-11T11:22:46.333 回答