包含一组用户定义的 项 元素。 MSBuild 项目中使用的每个项都必须指定为元素的 ItemGroup 子级。
<Project><ItemGroup>
Syntax
<ItemGroup Condition="'String A' == 'String B'"
Label="Label">
<Item1>... </Item1>
<Item2>... </Item2>
</ItemGroup>
属性和元素
以下部分介绍属性、子元素和父元素。
Attributes
| Attribute | Description |
|---|---|
Condition |
可选属性。 要评估的条件。 有关详细信息,请参阅 “条件”。 |
Label |
可选属性。 标识 .ItemGroup |
子元素
| 元素 | Description |
|---|---|
| 物品 | 定义生成过程的输入。 一个ItemGroup中可能有零个或多个Item元素。 |
除了泛型Item元素之外,ItemGroup 还允许表示项目类型的子元素,例如Reference,ProjectReference和 CompileCommon MSBuild 项目项中列出的其他项。
父元素
| 元素 | Description |
|---|---|
| 项目 | MSBuild 项目文件的必需根元素。 |
| 目标 | 该 ItemGroup 元素可以出现在元素内 Target 。 有关详细信息,请参阅 “目标”。 |
Example
下面的代码示例演示用户定义的项集合 Res 并在 CodeFiles 元素内 ItemGroup 声明。 项集合中的每个 Res 项都包含用户定义的子 ItemMetadata 元素。
<Project>
<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>
在简单的项目文件中,通常使用单个 ItemGroup 元素,但也可以使用多个 ItemGroup 元素。 使用多个 ItemGroup 元素时,项合并为单个 ItemGroup元素。 例如,某些项可能由导入文件中定义的单独 ItemGroup 元素包含。
ItemGroups 可以使用属性 Condition 应用条件。 在这种情况下,仅当满足条件时,这些项才会添加到项列表中。 请参阅 MSBuild 条件
该 Label 属性在一些生成系统中用作控制生成行为的一种方式。 只能在声明中使用它,作为创建更易于理解的 MSBuild 脚本的方法,或用作影响生成作的控件设置。