Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty an MSBuild ItemGroup

Tags:

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

like image 379
Zain Rizvi Avatar asked Oct 26 '11 22:10

Zain Rizvi


People also ask

What is ItemGroup in MSBuild?

In addition to the generic Item element, ItemGroup allows child elements that represent types of items, such as Reference , ProjectReference , Compile , and others as listed at Common MSBuild project items.

What is ItemGroup?

An item group is a collection of products which share similar attributes like color, production, features, or usage. Item groups can also be formed based on the markets in which they're sold or if they're similar in price.

What is MSBuild target?

A target element can have both Inputs and Outputs attributes, indicating what items the target expects as input, and what items it produces as output. If all output items are up-to-date, MSBuild skips the target, which significantly improves the build speed. This is called an incremental build of the target.


2 Answers

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> 
like image 159
Ritch Melton Avatar answered Sep 28 '22 04:09

Ritch Melton


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.
like image 36
weir Avatar answered Sep 28 '22 05:09

weir