This documentation is archived and is not being maintained.

How to: Add Templates to the New Project Dialog Box

A number of predefined project templates are installed during Visual Studio installation. For a complete list of predefined project templates, see Default Project Templates in Visual Studio. In addition to default project templates you can create custom or subtype-specific project templates. For example, the Smart Device subtype provides its own templates for Visual C# and Visual Basic projects. For instructions on how to create a custom template, see How to: Create Project Templates. In order to create a new project based on your custom template you need to add a custom template to the Visual Studio New Project dialog box. The template is added to the Project Types list in Other Languages node of the New Project dialog box. The icon associated with this new template is placed within Visual Studio Installed Templates, located in the Templates pane of the New Project dialog box.

To add a template to the New Project dialog box

  1. Provide a project factory for your project subtype.

    Public Class ProjectFactory
        Inherits FlavoredProjectFactory
        Private package As ProjectSubtype
    
        Public Sub New(ByVal package As ProjectSubtype)
            MyBase.New()
            Me.package = package
        End Sub
    

    public class ProjectFactory : FlavoredProjectFactory
    {
        private ProjectSubtype package;
    
        public ProjectFactory(ProjectSubtype package)
            : base()
        { 
            this.package = package;
        }
    
  2. Register your project with Visual Studio by using the ProvideProjectFactoryAttribute class.

    [Visual Basic]

    <MSVSIP.ProvideProjectFactory(GetType(ProjectFactory), "Task Project", "Task Project Files (*.vbproj);*.vbproj", "vbproj", "vbproj", "..\..\Templates\Projects")> _
    Public NotInheritable Class ProjectSubtype
    Inherits MSVSIP.Package
    

    [MSVSIP.ProvideProjectFactory(typeof(ProjectFactory), "Task Project", "Task Project Files (*.csproj);*.csproj", "csproj", "csproj", "..\\..\\Templates\\Projects")]
    public sealed class ProjectSubtype : MSVSIP.Package
    

    where,

    typeof(ProjectFactory) is the type of factory the VSPackage offers,

    "Task Project" is the name of the project and the name of the template,

    "Task Project Files (*.csproj);*.csproj" is the resource ID of the display string representing the project file extensions,

    "csproj" is the default project extension,

    "csproj" is the project extension supported by this project factory,

    "..\\..\\Templates\\Projects" is the directory containing the templates of this project factory.

  3. Instantiate and register your project factory with Visual Studio in Initialize() method of the VSPackage.

    Protected Overrides Sub Initialize()
        MyBase.Initialize()
    
        ' Create and register your project factory.
        Me.RegisterProjectFactory(New ProjectFactory(Me))
    End Sub
    

    protected override void Initialize()
    {
        base.Initialize();
    
        // Create and register your project factory.
        this.RegisterProjectFactory(new ProjectFactory(this));
    }
    

Note   This code example is part of a larger example provided in ProjectSubtype.

Show: