Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
MSBuild Reference
 ItemGroup Element (MSBuild)

  Switch on low bandwidth view
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
ItemGroup Element (MSBuild)

Contains a set of user-defined Item elements. Every item used in a MSBuild project must be specified as a child of an ItemGroup element.

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

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

Attributes

Attribute

Description

Condition

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

Child Elements

Element

Description

Item

Defines the inputs for the build process. There may be zero or more Item elements in an ItemGroup.

Parent Elements

Element

Description

Project

Required root element of an MSBuild project file.

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>
Community Content   What is Community Content?
Add new content RSS  Annotations
Project is not the only Parent element allowed      DaveD008 ... Vaccanoll   |   Edit   |   Show History

I've discovered, somewhat by accident, that it's also possible to have an ItemGroup element work nested in a Target element. Here's an example of what I mean:

<Target Name="SetMetaData">
<ItemGroup>
<MyItems Condition=" '%(MyItems.MyOtherMetaData)'=='true' " >
<MyMetaData>$(MyMetaDataValue)</MyMetaData>
</MyItems>
</ItemGroup>
</Target>


This makes it quite easy to add/ modify item metadata.

This fact may be well-known by experienced MSBuild users, but as a beginning-level MSBuild student, I rely heavily on these MSDN docs, and I've not seen this behavior documented anywhere in here.

--

This is only true in MSBuild 3.5. You also have to have ToolsVersion="3.5" defined in the project section or it will not work.

Vaccano

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker