ProjectItem Element (Visual Studio Item Templates)
Specifies a file that is included in the item template.
Not
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>
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. |
ReplaceParamenters |
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 |
---|---|
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="2.0.0"
xmlns="https://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
Tasks
How to: Create Multi-file Item Templates
Reference
Visual Studio Template Schema Reference