title | description | ms.date | ms.topic | f1_keywords | dev_langs | helpviewer_keywords | author | ms.author | manager | ms.subservice | |||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ItemGroup Element (MSBuild) |
Learn about the MSBuild ItemGroup element, which contains a set of user-defined Item elements. Every item must be a child of an ItemGroup. |
11/04/2016 |
reference |
|
|
ghogen |
ghogen |
mijacobs |
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
element.
<Project> <ItemGroup>
<ItemGroup Condition="'String A' == 'String B'"
Label="Label">
<Item1>... </Item1>
<Item2>... </Item2>
</ItemGroup>
The following sections describe attributes, child elements, and parent elements.
Attribute | Description |
---|---|
Condition |
Optional attribute. Condition to be evaluated. For more information, see Conditions. |
Label |
Optional attribute. Identifies the ItemGroup . |
Element | Description |
---|---|
Item | Defines the inputs for the build process. There may be zero or more Item elements in an ItemGroup . |
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.
Element | Description |
---|---|
Project | Required root element of an MSBuild project file. |
Target | Starting with .NET Framework 3.5, the ItemGroup element can appear inside a Target element. For more information, see Targets. |
The following code example shows the user-defined item collections Res
and 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
The 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.