Export (0) Print
Expand All
7 out of 32 rated this helpful - Rate this topic

How to: Manually Create Project Templates 

Visual Studio provides wizards to help you generate templates from projects that are open in the development environment. However, if you want to create a template outside of the development environment, you can use this procedure to manually assemble the source files of your application into a Visual Studio project template.

The process of creating a custom project template involves designing and developing the project as well as providing metadata about the project template.

Custom project templates require the following items:

  • The metadata file (*.vstemplate) that Visual Studio uses to define how to display the project in the development environment and, if you have specified the appropriate properties, to customize how the project is created in the development environment.

  • The project file.

  • The code files, such as Windows forms, Web forms, class files, and resource files.

All the items are compressed into a single .zip file. The .zip file must be placed in the location recognized by Visual Studio for custom project templates. Custom project templates are listed within each programming language folder in the My Templates section of the New Project dialog box. For more information, see How to: Locate and Organize Project and Item Templates.

To create a template manually

  1. Create a project.

  2. Modify or delete the files in the project, or add new files to the project.

  3. Edit the code files to indicate where parameter replacement should take place. For more information on parameter replacement, see How to: Substitute Parameters in a Template.

  4. Create an XML file and save it with a .vstemplate extension in the same directory as your project, but do not add it to the project in Visual Studio.

  5. Author the .vstemplate XML file to provide project template metadata. For more information, see the example in the following section.

  6. Select the files included in your template (including the .vstemplate file), right-click, select Send To, and click Compressed (zipped) Folder. The files that you previously extracted are compressed into a .zip file.

  7. Place the .zip template file in the Visual Studio project template directory. By default, this directory is My Documents\Visual Studio 2005\Templates\ProjectTemplates.

Example

This example shows a simple .vstemplate metadata file. The TemplateData element specifies the project type, name, description, and icon that are displayed in the New Project dialog box. The TemplateContent element specifies the name of the project file and the files that are in the project. In this example, the project file is named MyStarterKit.csproj, and includes the files that comprise a Visual C++ project.

<VSTemplate Type="Project" Version="2.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>
            <ProjectItem>Properties\AssemblyInfo.cs</ProjectItem>
            <ProjectItem>Properties\Resources.resx</ProjectItem>
            <ProjectItem>Properties\Resources.Designer.cs</ProjectItem>
            <ProjectItem>Properties\Settings.settings</ProjectItem>
            <ProjectItem>Properties\Settings.Designer.cs</ProjectItem>
        </Project>
    </TemplateContent>
</VSTemplate>

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.