How To Create Multi-Project Template Using Visual Studio 2017

Introduction

Visual Studio provides many in-built templates for creating a project. Project template allows a developer to create new projects based on your exported project. The developers are able to utilize their template for the new project dialog box. In this article, we will create a new project template for solution with multiple projects as per your client or product requirement, and use your project template for multiple developers. Visual Studio provides wizards to help you generate templates from projects that are open in the Integrated Development Environment (IDE).

Visual Studio 2017

Related Article

  1. You can refer to my previous article for creating a basic /single project template.

Create Solution

Let's start creating a new solution with multiple projects using Visual Studio 2017

Open Run > Type Devenev.Exe and press Enter. Go to New Project (Ctrl+Shift+N), Select any project type ( UWP ,Xamarin ,Class library,Web) and add multiple projects with your customization.

Visual Studio 2017

Export Project Template

Microsoft provides the easiest way to use Template Export Wizard to export project one by one, as given below.

Go to Project menu and click on "Export Template".

Visual Studio 2017

Export template Wizard

Select the Project Template option and chose the project one by one. Click on "Next". You can repeat this process for each project in the solution.

Visual Studio 2017

Project Template Details

Provide the project template name, description, and icon details. We need to generate project template for all the projects, so uncheck the "Automatically import the template" option and click on "Next".

Visual Studio 2017

The File Explorer should pop up with "My Exported Templates" where your newly exported all the project. If you want to customize the project, you can extract the folder and customize the .vstemplate file.

Visual Studio 2017

Solution Template

We have already created all the project.VStemplate. Now, we need to create the Root.vstemplate file for solutions with all the project references. 

Right click on Project >select New > select New Item >> and select XML file.

Visual Studio 2017

Root.vstemplate

You can add the following XML file and save as Root.vsTemplate from the exported project path.

Visual Studio 2017

  1. <Name> Provide the Solution Template Name
  2. <Description> Provide template details and description
  3. <ProjectType> Provide the project type category
  4. <CreateNewFolder> Provide new Folder details (true /False)
  5. <DefaultName> Provide default project name ++
  6. <ProvideDefaultName> Do you want to provide a default name (True/false)
  7. <ProjectCollection> Provide the all the project details
  8. $projectname$ is replace project on runtime
  1. <VSTemplate Version="3.0.0" Type="ProjectGroup" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">  
  2.   <TemplateData>  
  3.     <Name>DevEnvExe Mobile Application Template</Name>  
  4.     <Description>UWP based Windows mobile application with online and offline feature</Description>  
  5.     <ProjectType>CSharp</ProjectType>  
  6.     <ProjectSubType>  
  7.     </ProjectSubType>  
  8.     <SortOrder>1000</SortOrder>  
  9.     <CreateNewFolder>true</CreateNewFolder>  
  10.     <DefaultName>DevEnv_Template</DefaultName>  
  11.     <ProvideDefaultName>true</ProvideDefaultName>  
  12.     <LocationField>Enabled</LocationField>  
  13.     <EnableLocationBrowseButton>true</EnableLocationBrowseButton>  
  14.     <Icon>img.png</Icon>  
  15.   </TemplateData>  
  16.   <TemplateContent>  
  17.     <ProjectCollection>  
  18.             <ProjectTemplateLink ProjectName="$projectname$.Offline">  
  19.                 Dev_Offline\MyTemplate.vstemplate  
  20.             </ProjectTemplateLink>  
  21.             <ProjectTemplateLink ProjectName="$projectname$.Online">  
  22.                 DevEnv_Online\MyTemplate.vstemplate  
  23.             </ProjectTemplateLink>  
  24.         <ProjectTemplateLink ProjectName="$projectname$.Service">  
  25.                 DevEnv_Service\MyTemplate.vstemplate  
  26.             </ProjectTemplateLink>  
  27.         <ProjectTemplateLink ProjectName="$projectname$">  
  28.                 DevEnv_Template\MyTemplate.vstemplate  
  29.             </ProjectTemplateLink>  
  30.         </ProjectCollection>  
  31.   </TemplateContent>  
  32. </VSTemplate>  

We have done all the steps. I just want to add a template icon and Root.Vstemplate for the solution template. Now, zip the files in this folder by selecting the folder and files. Right click > Send to > Compressed (zipped) folder.


Visual Studio 2017

After zipping the file, move zip template to the following folder C:\Users\<usrname>\Documents\Visual Studio 2017\Templates\ProjectTemplates .

Visual Studio Project Template

You can now restart Visual Studio and go to New Project. Go to the Project template like below.

Visual Studio 2017

The following solution is created as per the given project name. Now, you can start development using your solution template.

Visual Studio 2017 

Summary

In this article, you learned how to create multi-project template using Visual Studio.

If you have any questions/ feedback/ issues, please write in the comment box.


Similar Articles