Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CreateItem vs ItemGroup

Tags:

msbuild

What is the difference between creating an item inside a target like this:

<Target Name="DoStuff">     <CreateItem Include="@(IntermediateAssembly)" >         <Output TaskParameter="Include" ItemName="FileWrites"/>     </CreateItem> </Target> 

and like this:

<Target Name="DoStuff">     <ItemGroup>         <FileWrites Include="@(IntermediateAssembly)" />     </ItemGroup> </Target> 

When would you use one or the other and why?

like image 1000
Jake Avatar asked Jun 02 '09 02:06

Jake


People also ask

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 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 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.


1 Answers

In versions of MSBuild prior to 3.5 you could not define properties or items inside of targets (like in your second example). So a task was used instead (CreateItem and CreateProperty)

If you are using ToolsVersion 3.5 then you don't need to use CreateItem anymore (though you still can if you prefer).

In the end they both create the item the same, with the same scope. Using the second syntax is more readable and setting up custom meta data is much easier (in my opinion).

NOTE: The 3.5 version of MSBuild is installed with .NET 3.5. Though you need to define ToolsVersion="3.5" in the Project tag of your MSBuild file to use 3.5 features.

In case you are wondering, I got most of this info from the book Inside the Microsoft® Build Engine: Using MSBuild and Team Foundation Build which I really liked (but am not affiliated with in any way).

like image 67
Vaccano Avatar answered Oct 15 '22 20:10

Vaccano