Tuesday, March 25, 2008

Remove Items From ItemGroups In MSBuild

The ability to remove entries from ItemGroups is one of the new features of MSBuild 3.5.

To remove an Item from an ItemGroup in MSBuild 2.0 you would have to create a new ItemGroup from the old one and skip the Item that you needed removed.

In MSBuild 3.5 we can achieve it by using the Remove parameter.

Example:

<ItemGroup>
<Files Include="a.cs" />
<Files Include="b.cs" />
<Files Include="c.cs" />
<Files Include="d.cs" />
<Files Include="e.cs" />
<Files Include="f.cs" />
<Files Include="g.cs" />
</ItemGroup>


Some times we want to restrict some data from this group in a target. In order to do it,  we should use the Remove parameter:



<ItemGroup>
<Files Remove="a.cs" />
<Files Remove="e.cs" />
<Files Remove="f.cs" />
</ItemGroup>


Read more at msdn.

No comments: