Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
MSBuild Reference
 Item Element (MSBuild)
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework General Reference
Item Element (MSBuild)

Updated: November 2007

Contains a user-defined item and its metadata. Every item used in a MSBuild project must be specified as a child of an ItemGroup element.

<Item Include="*.cs"
        Exclude="MyFile.cs"
        Condition="'String A'=='String B'" >
    <ItemMetadata1>...</ItemMetadata1>
    <ItemMetadata2>...</ItemMetadata2>
</Item>

The following sections describe attributes, child elements, and parent elements.

Attributes

Attribute

Description

Include

Required attribute.

The file or wildcard to include in the item.

Exclude

Optional attribute.

The file or wildcard to exclude in the item.

Condition

Optional attribute.

Condition to be evaluated. For more information, see MSBuild Conditions.

Child Elements

Element

Description

ItemMetadata

A user-defined item metadata key, which contains the item metadata value. There may be zero or more ItemMetadata elements in an item.

Parent Elements

Element

Description

ItemGroup

Grouping element for items.

Item elements define inputs into the build system, and are grouped into item collections based on their user-defined collection names. These item collections can be used as parameters for tasks, which use the individual items contained in the collection to perform the steps of the build process. For more infomration, see MSBuild Items.

Using the notation @(myType) allows a collection of items of type myType to be expanded into a semicolon (;) delimited list of strings, and passed to a parameter. If the parameter is of type string, then the value of the parameter is the list of elements separated by semicolons. If the parameter is an array of strings (string[]), each element is inserted into the array based on the location of the semicolons. If the task parameter is of type ITaskItem[], the value is the contents of the item collection with any metadata attached. To delimit each item with a character other than a semicolon, use the syntax @(myType, 'separator').

The MSBuild engine is able to evaluate wildcards such as * and ? as well as recursive wildcards such as /**/*.cs. For more information, see MSBuild Items.

The following code example shows how to declare two items of type CSFile. The second declared item contains metadata with myAttribute set to HelloWorld.

<ItemGroup>
    <CSFile Include="engine.cs; form.cs" />
    <CSFile Include="main.cs" >
        <MyMetadata>HelloWorld</MyMetadata>
    </Item>
</ItemGroup>
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker