ItemDefinitionGroup 元素 (MSBuild)ItemDefinitionGroup element (MSBuild)

使用 ItemDefinitionGroup 元素可定义一组项定义,这些项定义默认为应用到项目中的所有项的元数据值。The ItemDefinitionGroup element lets you define a set of Item Definitions, which are metadata values that are applied to all items in the project, by default. ItemDefinitionGroup 取代使用 CreateItem 任务CreateProperty 任务的需要。ItemDefinitionGroup supersedes the need to use the CreateItem task and the CreateProperty task. 有关详细信息,请参阅项定义For more information, see Item definitions.

<Project> <ItemDefinitionGroup>

语法Syntax

<ItemDefinitionGroup Condition="'String A' == 'String B'">
    <Item1>... </Item1>
    <Item2>... </Item2>
</ItemDefinitionGroup>

特性和元素Attributes and elements

下列各节描述了特性、子元素和父元素。The following sections describe attributes, child elements, and parent elements.

特性Attributes

特性Attribute 描述Description
Condition 可选特性。Optional attribute. 要计算的条件。Condition to be evaluated. 有关详细信息,请参阅条件For more information, see Conditions.

子元素Child elements

元素Element 描述Description
ItemItem 定义生成过程的输入。Defines the inputs for the build process. ItemDefinitionGroup 中可能没有或有一些 Item 元素。There may be zero or more Item elements in an ItemDefinitionGroup.

父元素Parent elements

元素Element 描述Description
ProjectProject MSBuild 项目文件必需的根元素。Required root element of an MSBuild project file.

示例Example

下面的代码示例定义 ItemDefinitionGroup 中的两个元数据项,m 和 n。The following code example defines two metadata items, m and n, in an ItemDefinitionGroup. 在本例中,默认元数据“m”应用于项“i”,这是由于项“i”没有显式定义元数据“m”。In this example, the default metadata "m" is applied to Item "i" because metadata "m" is not explicitly defined by Item "i". 但是,默认元数据“n”无法应用于项“i”,这是由于元数据“n”已经由项“i”定义。However, default metadata "n" is not applied to Item "i" because metadata "n" is already defined by Item "i".

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemDefinitionGroup>
        <i>
            <m>m1</m>
            <n>n1</n>
        </i>
    </ItemDefinitionGroup>
    <ItemGroup>
        <i Include="a">
            <o>o1</o>
            <n>n2</n>
        </i>
    </ItemGroup>
    ...
</Project>

请参阅See also