Share via

CreateItem Task


This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

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


This task is deprecated. Starting with .NET Framework 3.5, item groups may be placed within Target elements. For more information, see Items.


The following table describes the parameters of the CreateItem task.

Parameter Description
AdditionalMetadata Optional String array 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[] output parameter.

Specifies the items to exclude from the output item collection. This parameter can contain wildcard specifications. For more information, see Items and How to: Exclude Files from the Build.
Include Required ITaskItem[]parameter.

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

If True, only apply the additional metadata if they do not already exist.


In addition to the parameters listed above, this task inherits parameters from the TaskExtension class, which itself inherits from the Task class. For a list of these additional parameters and their descriptions, see TaskExtension Base Class.


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. 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 file2.resx, both with metadata entries for MyMetadata. The MySourceItems item collection is unchanged.

<Project xmlns="">  
        <MySourceItems Include="file1.resx;file2.resx" />  
    <Target Name="NewItems">  

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")

file2.resx (MyMetadata="Hello")

See Also

Task Reference