Create Your Own Project Template in Visual Studio

We often repeat the same kind of project, adding the same references, classes and more. In this article I'm sharing how to create your own project template so that you save time by selecting the template from "New Project" template gallery. Use the following procedure.

Start Visual Studio and create a new project of any variety of your choice.

Picture 1 - Create Project of your choice

Do whatever you find to be repetitive that you often do in your projects. For example, I work with MySQL often and for that I need referenced every time. By default, no preinstalled template gives me this assembly already added to the project. I add it manually every time so I'm going to add this to my project.

Picture 2 - Adding Reference to MySql.Data

Picture 3

I'll also add a few more items for demonstration purposes.

Picture 4 (Added an image folder, a .js file, a Repository class)

After you're done adding the references/classes/items to your project, go to "File" > "Export Template".

Picture 5- Export Template

At this phase it will ask you to save the changes made in your project if you haven't done that yet.

The Export Template Wizard offers you two flavors. The first is "Project template" and the second is "Item template".

A project template allows you to create a new project based on your exported project with all the files/codes/references already in it whereas an item template allows a user to add your item to one of their existing projects. A project template will appear in the New Project dialog box whereas an item template in the "Add New Item" of any project.

This wizard also gives you an option to select a project to export from the list if you have many projects added to your current solution. Select the project you want to export if you have more than one.

Picture 6- Export Template Wizard

Click "Next", it will navigate to the template options dialog box.

Picture 7- Template Options

  • Template Name: The friendly name for the template that Visual Studio displays in the list of templates. It is recommended to keep it simple and around 50-60 characters. Mine is "SampleProject".

  • Template Description: A short description that provides a little more detail about the template's purpose (in the right pane of New Project dialog box). You provide here what this template should be used for. I left this blank intentionally.

  • Icon Image: A small image that represents the icon for the item. I've selected my Headshot.jpg.

  • Preview Image: A larger image that provides a preview of what the template looks like. I've select my Headshot.jpg here also.

  • Output Location: The location where the wizard stores exported items. This is the initial storage location of your templates. To be clear, they are not usable in Visual Studio when they are just created. To make them useable in Visual Studio, you need to check "Automatically Import the Template into Visual Studio". Leave this as-is unless you are storing your templates on a network share somewhere. If you do change this value then make sure you use the new location consistently when you create templates or you will wind up forgetting where you put them.

  • Automatically Import The Template Into Visual Studio: Lets you decide whether you want to import the template right away or want to do it manually later. This "import" is just a copy of the .zip file created in the appropriate location in My Documents\Visual Studio <version>\Templates\ItemTemplates. By doing this, the template immediately becomes usable in Visual Studio.

  • Display An Explorer Window On The Output Files Folder: Opens up the location where the template files are stored after they are created. This is useful when you want to see the .zip file that is created. It's interesting the first few times you do it, but then it's pretty much a waste of time. You will wind up turning off this option most of the time.

Click "Finish". It will create the template and open the template folder in file explorer. The same as for the Project template, if you select an Item template in Export Template Wizard then it will ask you to select an item to export like this:

Picture 8- Item template (Select an item to export from the selected project)

Navigating further by clicking "Next" will ask you to select any reference from the project to be attached with the item template.

Note: A user will be unable to use this item template if the referenced assemblies are not installed on his/her machine.

Picture 9 - Select assembly references

Click "Finish" and it will open the template location in the file explorer.

Picture 10 - Template Directory

That's all it takes to create a project template and now you can use it for new projects ahead. You will find it New Projects dialog box:

Picture 11- (SampleProject template is present in New Project dialog box)

You can see it shows the preview image in the right pane of the dialog box that I selected when creating this template (my headshot).

If you choose this project template then you will see that all your flavors are already added.

Picture 12 - NewProject_from_SampleProject template

The same as above, you will see the item template while adding a new item to a project:

Picture 13 - SampleItem - Item template

I hope you enjoyed reading this article.

Feedback and comments are highly appreciated. Follow for more!

Up Next
    Ebook Download
    View all
    View all