Recently at work we had to create a lot of microservices where we required to copy-paste lot of files from one sample solution to the specific service implementations. The necessity of this approach comes from the many small differences between each service.
Of course the common code was extracted to shared libraries but this was just a partial solution. Now that we can grasp their usefulness, let’s see how to create visual studio templates!
Different options for creating templates
There are three ways to create a project template:
- Exporting a template from an existing project
- Creating a template project
- Exporting an existing project then copying its content to a template project
In this tutorial we will explore the first option.
Exporting a template from an existing project
1. Create a new project or open an existing one. For this tutorial we will use an incredibly simple web crawler console project.
2. Open the File menu, and click on the Export Template… option.
3. Make sure the Project template radio button is selected then click on the Next button.
4. On the second window of the Export Template Wizard provide the template name, description, an icon and a preview image. From these properties, the template name is the only one which is a required field.
There are also some options such as the “Automatically import the template into Visual Studio” option whose checkbox is selected by default. If you leave it as selected, then the resulting project template zip file will be copied to the C:\Users\\Documents\Visual Studio 2013\Templates\ProjectTemplates folder.
The next time you open the Create new project window, you will find there your newly created template. (If you use this example project, it will be under the Visual C# section)
5. Click on the Finish button.
Details of the created template
The different info you provided for your template will appear this way:
Some thoughts of the icon and preview image you can use:
- You can use png, gif, jpg and ico formats for both the preview and the icon images.
- The preview image will be displayed at the right side of the New project window (see image above) and will be resized so it fits a 200px X 200px square.
- The icon image will be displayed in the middle of the window and will be resized to fit a 32px X 32px square if the Medium icons option is selected or it will be resized to fit a 16px X 16px square if the small icons option is selected.
Let see an example where your images are not as fancy as the first time 😉
You can downloaded the source code from here.