Folder Element (Visual Studio Project 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 Folder Element (Visual Studio Project Templates).

Specifies a folder that will be added to the project.

<VSTemplate>
<TemplateContent>
<Project>
<Folder>

<Folder Name="Project Folder">  
    <Folder> ... </Folder>  
    <ProjectItem> ... </ProjectItem>  
</Folder>  

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

Attributes

AttributeDescription
NameRequired attribute.

The name of the project folder.
TargetFolderNameOptional attribute.

Specifies the name to give the folder when a project is created from the template. This attribute is useful for using parameter replacement to create a folder name or naming a folder with an international string that cannot be used directly in the .zip file.

Child Elements

ElementDescription
FolderSpecifies a folder to add to the project. Folder elements can contain child Folder elements.
ProjectItemSpecifies a file to add to the project.

Parent Elements

ElementDescription
ProjectOptional child element of TemplateContent.

Folder is an optional child of Project.

You can use any of the following methods to to organize project items into folders in a template:

  • Include the folders in the template .zip file, and add them to the project in the .vstemplate file by specifying the path to the file in the ProjectItem elements, with no Folder elements. This is the recommended method. For example:

    ...

    <ProjectItem>\Folder\item.cs</ProjectItem>

    <ProjectItem>Form1.cs</ProjectItem>

    ...

  • Include the folders in the template .zip file, and add them to the project in the .vstemplate file with Folder elements. For example:

    ...

    <Folder name="Folder">

    <ProjectItem>item.cs</ProjectItem>

    </Folder>

    <ProjectItem>Form1.cs</ProjectItem>

    ...

  • Do not include folders in the template .zip file, but add folders using the TargetFileName attribute of the ProjectItem element. For example:

    ...

    <ProjectItem TargetFileName="\Folder\item.cs">item.cs</ProjectItem>

    <ProjectItem>Form1.cs</ProjectItem>

    ...

The following example illustrates the metadata for a project template for a Visual C# Windows application.

<VSTemplate Type="Project" Version="3.0.0"  
    xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">  
    <TemplateData>  
        <Name>My template</Name>  
        <Description>A basic template</Description>  
        <Icon>TemplateIcon.ico</Icon>  
        <ProjectType>CSharp</ProjectType>  
    </TemplateData>  
    <TemplateContent>  
        <Project File="MyTemplate.csproj">  
            <ProjectItem>Form1.cs<ProjectItem>  
            <ProjectItem>Form1.Designer.cs</ProjectItem>  
            <ProjectItem>Program.cs</ProjectItem>  
            <Folder Name="Properties">  
                <ProjectItem>AssemblyInfo.cs</ProjectItem>  
                <ProjectItem>Resources.resx</ProjectItem>  
                <ProjectItem>Resources.Designer.cs</ProjectItem>  
                <ProjectItem>Settings.settings</ProjectItem>  
                <ProjectItem>Settings.Designer.cs</ProjectItem>  
            </Folder>  
        </Project>  
    </TemplateContent>  
</VSTemplate>  

Visual Studio Template Schema Reference
Creating Project and Item Templates
ProjectItem Element (Visual Studio Item Templates)

Show: