Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top