Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Reference
 ProjectItem Element (Visual Studio ...
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual Studio
ProjectItem Element (Visual Studio Item Templates)

Updated: November 2007

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

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

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.

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

TemplateContent

Specifies 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="2.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>
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker