29Oct

Create custom project templates in Visual Studio

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.

solution skelton

 

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

export template

 

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’

project selection

 

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.

proj select

 

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.

template

 

Extract all the exported templates into a separate folder

extract the zip

 

Now we need to create .vstemplate file by referring the all the exported templates from the solution file.

Go to, File -> New -> File…new file

 

As the .vstemplate file is in the form of XML format, choose the XML file

select xml

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.Business\MyTemplate.vstemplate

      ProjectTemplateLink>

      <ProjectTemplateLink ProjectName="$projectname$.DataAccess">

        Project1.DataAccess\MyTemplate.vstemplate

      ProjectTemplateLink>

      <ProjectTemplateLink ProjectName="$projectname$.Services">

        Project1.Services\MyTemplate.vstemplate

      ProjectTemplateLink>

      <ProjectTemplateLink ProjectName="$projectname$WebPortal">

        Project1WebPortal\MyTemplate.vstemplate

      ProjectTemplateLink>

    ProjectCollection>

  TemplateContent>

VSTemplate>

Save this XML file to the same location where the templates are extracted

save template

 

saved tempalte

 

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.

templ icon

 

Select all the files from the root directory and compress into .zip file format

zip the files

Now the final template file is created and ready to deploy it.

temlate zip

Go to Documents\Visual Studio Version\Templates\ProjectTemplates and create a new folder to separate your template from the default templates of visual studio.

template group name

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.

select project

The project is created with a solution where you will see a list of projects are get created from the Skelton solution.

created solution

Thanks for reading and hope this article helps you in better..... 

 

Related

What are Frames? How to handle frames in Selenium WebDriver with C#?

IFrame (FullForm: Inline Frame) is an HTML document that is included in another HTML document and is...

Read More >

What is Synchronization? Handling Synchronization in Selenium WebDriver using C#:

Synchronization meaning: when two or more components involved to perform any action, we expect these...

Read More >

Sending Test reports by Email using Office 365, Gmail

Wouldn’t it be great if Test Report are sent automatically across team as soon the Test Execut...

Read More >

Token Based Authentication for Web API's

Securing ASP.NET Web API using Custom Token Based AuthenticationProviding a security to the Web API&...

Read More >

Assertions in Coded UI

Let us discuss how to add assertions in coded UI. Assertions are checkpoints/benchmarks to UI c...

Read More >

ASP.NET: Audit Trail Implementation using Entity Framework

When you are working with certain projects which involves the Customer records, you might need to tr...

Read More >

Create Restful service using Web API

What is Asp.Net Web API?Asp.Net Web API is a framework for building HTTP services that can be consum...

Read More >

Dependency Injection on SignalR

                &nbs...

Read More >

Share

Comments

Thanks for sharing this.
10/4/2019 12:08:21 PM | Reply

Post a Comment

  • Recent
  • Popular
  • Tag
Tags
Monthly Archive
Subscribe
Name

Contact Us
  • *
  • *