ProjectItem element (Visual Studio item templates)

Specifies a file that is included in the item template.

Note

The ProjectItem element accepts different attributes depending on whether the template is for a project or an item. This topic explains the ProjectItem element for item. For an explanation of the ProjectItem element for project templates, see ProjectItem element (Visual Studio project templates).

<VSTemplate> <TemplateContent> <ProjectItem>

Syntax

<ProjectItem
    SubType="Form/Component/CustomControl/UserControl"
    CustomTool="string"
    ItemType="string"
    ReplaceParameters="true/false"
    TargetFileName="TargetFileName.ext">
        FileName.ext
</ProjectItem>

Attributes and elements

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

Attributes

Attribute Description
SubType Optional attribute.

Specifies the subtype of an item in a multi-file item template. This value is used to determine the editor that Visual Studio will use to open the item.
CustomTool Optional attribute.

Sets the CustomTool for the item in the project file.
ItemType Optional attribute.

Sets the ItemType for the item in the project file.
ReplaceParameters Optional attribute.

A Boolean value that specifies whether the item has parameter values that must be replaced when a project is created from the template. Default value is false.
TargetFileName Optional attribute.

Specifies the name of the item that is created from the template. This attribute is useful for using parameter replacement to create an item name.

Child elements

None.

Parent elements

Element Description
TemplateContent Specifies the contents of the template.

Text value

A text value is required.

A string that represents the name of a file in the template .zip file.

Remarks

ProjectItem is an optional child of TemplateContent.

The TargetFileName attribute can be used to rename files with parameters. For example, if the file MyFile.vb exists in the root directory of the template .zip file, but you want the file to be named based on the file name provided by the user in the Add New Item dialog box, you would use the following XML:

<ProjectItem TargetFileName="$fileinputname$.vb">MyFile.vb</ProjectItem>

When an item is created from this template, the file name will be based on the name the user entered in the Add New Item dialog box. This is useful when creating multi-file item templates. For more information, see How to: Create multi-file item templates and Template parameters.

Example

The following example illustrates the metadata for the standard item template for a Visual C# class.

<VSTemplate Type="Item" Version="3.0.0"
    xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
    <TemplateData>
        <Name>MyClass</Name>
        <Description>My custom C# class.</Description>
        <Icon>Icon.ico</Icon>
        <ProjectType>CSharp</ProjectType>
        <DefaultName>MyClass.cs</DefaultName>
    </TemplateData>
    <TemplateContent>
        <ProjectItem ReplaceParameters="true">MyClass.cs</ProjectItem>
    </TemplateContent>
</VSTemplate>

See also