We recommend using Visual Studio 2017

ProjectItem Element (Visual Studio Item Templates)

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at ProjectItem Element (Visual Studio Item Templates).

Specifies a file that is included in the item template.

System_CAPS_ICON_note.jpg 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>

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

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

Attributes

AttributeDescription
SubTypeOptional 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.
CustomToolOptional attribute.

Sets the CustomTool for the item in the Project file.
ItemTypeOptional attribute.

Sets the ItemType for the item in the Project file.
ReplaceParametersOptional 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.
TargetFileNameOptional 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

ElementDescription
TemplateContentSpecifies the contents of the template.

A text value is required.

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

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.

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>  

Visual Studio Template Schema Reference
Creating Project and Item Templates
How to: Create Multi-file Item Templates
Template Parameters

Show: