You can use the ‘VSIX Project’ template to create a Visual Studio extension. This project type is installed as part of the Visual Studio SDK and you will need it to complete the exercise in this post.
1. Create a project which you wish to serve as the basis for your new project template. In this example, we will create a Console Application.
2. Make some changes to the application and how you would like it to behave as a project template. For this example, let’s rename Program.cs to Start.cs and also add a new text file called ReadMe.txt.
3. Once everything is to your liking, select “File > Export Template” from the Visual Studio menu. You will want to select “Project Template” as the template type and select the project from your solution (if following the demo, there will be only 1) from the dropdown. Click ‘Next’.
4. Specify the details about your template. Give it a name, a description, and optionally an image if you would like. Be sure to uncheck the ‘Automatically import the template into Visual Studio’. We will be bundling this into a VSIX package so you can deploy it to others as well. Note: This will export the template to “C:\Users\your_name\Documents\Visual Studio your_version\My Exported Templates\” by default.
5. Close your current solution, and create a new project of type “Extensibility > VSIX Project”. (note: If you do not see this template, ensure you installed the Visual Studio SDK as noted at the beginning of this post).
6. Update the VSIX manifest file (which should open by default) and specify details for ‘Product name’, ‘Description’, and ‘Author’.
7. Right click your new VSIX project, and select “Add > Existing Item”. Navigate to the export folder from Step #4 and select the .zip file that was created for you.” (Note: You may need to change the file type filter to “All Files (*.*)”).
8. Update the properties for the item you just added to be “Copy to Output Directory: Copy always”.
9. Back in your VSIX manifest file, select the “Assets” tab on the left rail. Select “New” and specify the Type as ‘Microsoft.VisualStudio.ProjectTemplates’. For ‘Source’ specify “File on the file system” and specify the .zip file you just imported in step #7. It should be in the root of the project folder. Click “Ok” to continue.
10. Navigate to the bin\Debug folder of your VSIX project folder in explorer. You should now see a VSIX file located here. Double click this file, and install the extension. Then close Visual Studio, and re-open it. If you navigate to “Tools > Extensions and Updates” then click “Templates” you will see your new Visual Studio template. Congrats! This is also navigable in the ‘New Project’ window under “Visual C#” (or Visual Basic” if you did this tutorial using Visual Basic).
Optional extras: If you want to change the location that the template installs to another folder, you will need to make some changes. We will, for this example, want our Console Application to appear inside “Visual C# > Windows Desktop”.
11. Navigate to the “bin\debug” folder of your VSIX project in explorer (same as Step #10). Right click your VSIX file and change the extension to .zip. Unzip the contents to a folder of the same name. You should see something like the following.
12. Go into the ‘ProjectTemplates’ folder, and add a new folder called “CSharp”, and below “CSharp” add a folder called “Windows”. Move the original .zip file from “\ProjectTemplates\Your%20%Plugin%20%Name.zip” to “\ProjectTemplates\CSharp\Windows\Your%20%Plugin%20%Name.zip”. Go back to the root folder of the zip that you unpacked and re-archive everything into “YourVSIXTemplate.zip”. Rename the .zip file to .vsix extension.
Important note: You will want to mirror the folder structure located at ‘\Common7\IDE\ProjectTemplates’. On my machine this was “C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ProjectTemplates”.
13. Inside Visual Studio, go to “Tools > Extensions and Updates” and uninstall your template you installed from Step #10. Close Visual Studio. Run the VSIX you modified from Step #12. You will now see your template in the proper location.