Search code examples
visual-studio-addinsenvdtevsxvspackagevs-extensibility

How to integrate a custom Project Template and Wizard into Visual Studio package?


Current Situation

I have created a Custom Project template with an attached wizard which will ask the user for some options and it will generate some code (for instance: INIT method, some objects initialization). I have deployed this via the VSIX Project and everything is fine.

The Goal

I have also an empty VS package. So My question is: How to import the template and the wizard into the package? Because I want to be able to update the package later on with menu items etc.

Problems

There is little info on the net about how to create and extend VS Package. I followed this tutorial. But there I have created a Project template which is basic and since I don't know how to extended it, I think it will be a lot easier to import an already created Project template with a wizard.

In Other Words

I want my final product to be just the same as C++ win32 console application (which appears in the c++ section. When clicked - wizard supports the user for generating a new project with his preferences) but for C# as well.

Extra Info

I read that Add ins are deprecated in the newer versions of VS as well as Macros. Therefore I chose VS Package Project System (more extensible than custom templates). I saw some explanation about A Project SubType (a.k.a ProjectFlavor - lets you customize or flavor the behavior of the project systems of Visual Studio) but I did not found any tutorials or samples except Managed Package Framework for Projects (it's too complex for me).


Solution

  • Assumptions

    For simplicity, I'm going to assume the following.

    1. You are creating a Project Template which creates a new project for a project system that is already supported by Visual Studio. For example, you might be creating a template which creates a new C# project.
    2. You are using Visual Studio 2012 or newer to create your extension.
    3. You want this extension to be usable in Visual Studio 2012 and newer.
    4. Your wizard customizations to the project are more complicated than can be performed by creating a "simple" project followed by automatically installing one or more NuGet packages (installation of NuGet packages as part of creating a new project does not require a custom wizard).

    Design Strategy

    The general design of your final extension will be the following.

    • Your extension will comprise of both the project template and an assembly containing your IWizard implementation.
    • The extension will be bundled into a single .vsix file for distribution.

    This design allows you to update your template, wizard, or both at any point in the future by simply creating a new version of your .vsix.

    Implementation

    Since there are many steps, I created a repository on GitHub to show the complete process.

    https://github.com/tunnelvisionlabs/VsixWizardSample