ItemGroup element (MSBuild)
Contains a set of user-defined Item elements. Every item used in an MSBuild project must be specified as a child of an
<ItemGroup Condition="'String A' == 'String B'" Label="Label"> <Item1>... </Item1> <Item2>... </Item2> </ItemGroup>
Attributes and elements
The following sections describe attributes, child elements, and parent elements.
||Optional attribute. Condition to be evaluated. For more information, see Conditions.|
||Optional attribute. Identifies the
|Item||Defines the inputs for the build process. There may be zero or more
In addition to the generic
Item element, ItemGroup allows child elements that represent types of items, such as
Compile, and others as listed at Common MSBuild project items.
|Project||Required root element of an MSBuild project file.|
|Target||Starting with .NET Framework 3.5, the
The following code example shows the user-defined item collections
CodeFiles declared inside of an
ItemGroup element. Each of the items in the
Res item collection contains a user-defined child ItemMetadata element.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <Res Include = "Strings.fr.resources" > <Culture>fr</Culture> </Res> <Res Include = "Dialogs.fr.resources" > <Culture>fr</Culture> </Res> <CodeFiles Include="**\*.cs" Exclude="**\generated\*.cs" /> <CodeFiles Include="..\..\Resources\Constants.cs" /> </ItemGroup> ... </Project>
In a simple project file, you normally use a single
ItemGroup element, but you can also use multiple
ItemGroup elements. When multiple
ItemGroup elements are used, items are combined into a single
ItemGroup. For example, some items might be included by a separate
ItemGroup element that's defined in an imported file.
ItemGroups can have conditions applied by using the
Condition attribute. In that case, the items are only added to the item list if the condition is satisfied. See MSBuild conditions
Label attribute is used in some build systems as a way to control build behaviors. You can use it only in declarations, as a way to create more understandable MSBuild scripts, or as a control setting to affect build actions.