Visual studio installation comes with the various predefined project templates, and we can use one of these templates (like console application, class library, ASP.NET web application, etc) to create a new project.
We can create custom project templates and have they appear in create new project dialog under the project selection templates.
Here I would show you the step by step procedure on how to build the custom solution template with multiple projects, configuring it in visual studio and have it using while creating the new project.
For the very first step, create a solution with the set of projects which you would like to create a template. Here I have created a simple solution (is a Skelton) with four projects for building web application. Now, I will show you how to create a template using this solution, so that next time same solution would be created whenever I need to build web application.
In order to create this solution as a template, we need to create .vstemplate file for each of the project in the above solution. For this, the simplest way is to use the export template wizard from the visual studio.
Go to File -> Export Template… as shown below
As we are creating the Project templates for the given solution, select the ‘Project template’ radio option, select a project name from the dropdown and click on ‘Next’
Fill the next wizard as you wish and uncheck the ‘Automatically import the template into Visual Studio’ option. If you check this, the exported project template will import into visual studio and can choose the imported template while creating a new project. As we are focusing the project template for entire solution, for now we will leave it with uncheck.
Finally click on ‘Finish’ button.
Repeat the above export wizard step for each project in the visual studio. The exported templates are in the form of .zip file. If you go inside the any exported template, you will see a MyTemplate.vstemplate as shown below.
Extract all the exported templates into a separate folder
Now we need to create .vstemplate file by referring the all the exported templates from the solution file.
Go to, File -> New -> File…
As the .vstemplate file is in the form of XML format, choose the XML file
Copy and paste the below template content into the newly added XML file
<VSTemplate Version="3.0.0" Type="ProjectGroup" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005"> <TemplateData> <Name>Canarys Web ProjectName> <Description>A project template for building ASP.NET application along with Business layer, Data access layer and Service layerDescription> <ProjectType>CSharpProjectType> <ProjectSubType> ProjectSubType> <SortOrder>1000SortOrder> <CreateNewFolder>trueCreateNewFolder> <DefaultName>CanarysWebProjectDefaultName> <ProvideDefaultName>trueProvideDefaultName> <LocationField>EnabledLocationField> <EnableLocationBrowseButton>trueEnableLocationBrowseButton> <Icon>CanarysWebProject.pngIcon> TemplateData> <TemplateContent> <ProjectCollection> <ProjectTemplateLink ProjectName="$projectname$.Business"> Project1.BusinessMyTemplate.vstemplate ProjectTemplateLink> <ProjectTemplateLink ProjectName="$projectname$.DataAccess"> Project1.DataAccessMyTemplate.vstemplate ProjectTemplateLink> <ProjectTemplateLink ProjectName="$projectname$.Services"> Project1.ServicesMyTemplate.vstemplate ProjectTemplateLink> <ProjectTemplateLink ProjectName="$projectname$WebPortal"> Project1WebPortalMyTemplate.vstemplate ProjectTemplateLink> ProjectCollection> TemplateContent> VSTemplate> |
Save this XML file to the same location where the templates are extracted
As you can observe that, the template file has the name of the icon which is used by the root template. Place the icon image in the root directory where the .vstemplate file is located.
Select all the files from the root directory and compress into .zip file format
Now the final template file is created and ready to deploy it.
Go to DocumentsVisual Studio VersionTemplatesProjectTemplates and create a new folder to separate your template from the default templates of visual studio.
You are almost done. your template is ready to use. Go to visual studio -> create new project dialog
You will see the newly created template as shown below. Give the name of the project and click on ‘Ok’ button.
The project is created with a solution where you will see a list of projects are get created from the Skelton solution.
Thanks for reading and hope this article helps you in better…..