CreateItem TaskĀ 

Populates item collections with the input items. This allows items to be copied from one list to another.

Attributes

The following table describes the parameters of the CreateItem task.

Parameter Description

AdditionalMetadata

Optional String parameter.

Specifies additional metadata to attach to the output items. Specify the metadata name and value for the item with the following syntax:

MetadataName = MetadataValue

Multiple metadata name/value pairs should be separated with a semicolon. If either the name or the value contains a semicolon or any other special characters, they must be escaped. For more information, see How To: Escape Special Characters in MSBuild.

Exclude

Optional ITaskItem[] parameter.

Specifies the items to exclude from the output item collection. This parameter can contain wildcard specifications. For more information, see MSBuild Items and How To: Build all Files in a Directory Except One.

Include

Optional ITaskItem[] output parameter.

Specifies the items to include in the output item collection. This parameter can contain wildcard specifications.

Example

The following code example creates a new item collection named MySourceItemsWithMetadata from the item collection MySourceItems. The CreateItem task populates the new item collection with the items in the MySourceItems item collection that contain MyAddMetadata values of true. It then adds an additional metadata entry named MyMetadata with a value of Hello to each item in the new collection.

After the task is executed, the MySourceItemsWithMetadata item collection contains the items file1.resx and file3.resx, both with metadata entries for MyAddMetadata and MyMetadata. The MySourceItems item collection is unchanged.

<Project xmlns="https://schemas.microsoft.com/developer/msbuild/2003">

    <ItemGroup>
        <MySourceItems Include="file1.resx;file3.resx">
            <MyAddMetadata>true</MyAddMetadata>
        </MySourceItems>
        <MySourceItems Include="file2.resx">
            <MyAddMetadata>false</MyAddMetadata>
        </MySourceItems>
    </ItemGroup>

    <PropertyGroup>
        <MyValue>Hello</MyValue>
    </PropertyGroup>

    <Target Name="NewItems">

        <CreateItem
            Include="@(MySourceItems)"
            Condition="'%(MyAddMetadata)'=='true'"
            AdditionalMetadata="MyMetadata=$(MyValue)">

           <Output
               TaskParameter="Include"
               ItemName="MySourceItemsWithMetadata"/>
        </CreateItem>

    </Target>

</Project>

The following table describes the value of the output item after task execution. Item metadata is shown in parenthesis after the item.

Item collection Contents

MySourceItemsWithMetadata

file1.resx (MyMetadata="Hello")

file3.resx (MyMetadata="Hello")

See Also

Concepts

MSBuild Tasks

Other Resources

MSBuild Task Reference