Is there a way to remove the contents of an ItemGroup without resorting to Targets? I'm looking for something equivalent to:

<ItemGroup>
  <MyItemGroup Remove="@(MyItemGroup)"/>
</ItemGroup>

Thanks

有帮助吗?

解决方案

Now there is.

What's New in MSBuild 15

  • Item Element outside targets has a new Update attribute. Also, the restriction on the Remove attribute has been eliminated.

其他提示

No, as the documentation states, Remove can only be included in a ItemGroup inside a Target. I'm not sure why using a Target is an issue in your case, but if want to use the 'Remove' step for every build config, then add it to one of the BeforeXXXX AfterXXX hooks, like BeforeBuild.

ItemGroup 'Remove' Documentation

Starting in the .NET Framework 3.5, Target elements may contain ItemGroup elements that may contain item elements. These item elements can contain the Remove attribute, which removes specific items (files) from the item type. For example, the following XML removes every .config file from the Compile item type.

<Target>
  <ItemGroup>
    <Compile Remove="*.config"/>
  </ItemGroup>
</Target>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top