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).
Related Article
- 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.
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".
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.
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".
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.
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.
Root.vstemplate
You can add the following XML file and save as Root.vsTemplate from the exported project path.
- <Name> Provide the Solution Template Name
- <Description> Provide template details and description
- <ProjectType> Provide the project type category
- <CreateNewFolder> Provide new Folder details (true /False)
- <DefaultName> Provide default project name ++
- <ProvideDefaultName> Do you want to provide a default name (True/false)
- <ProjectCollection> Provide the all the project details
- $projectname$ is replace project on runtime
- <VSTemplate Version="3.0.0" Type="ProjectGroup" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
- <TemplateData>
- <Name>DevEnvExe Mobile Application Template</Name>
- <Description>UWP based Windows mobile application with online and offline feature</Description>
- <ProjectType>CSharp</ProjectType>
- <ProjectSubType>
- </ProjectSubType>
- <SortOrder>1000</SortOrder>
- <CreateNewFolder>true</CreateNewFolder>
- <DefaultName>DevEnv_Template</DefaultName>
- <ProvideDefaultName>true</ProvideDefaultName>
- <LocationField>Enabled</LocationField>
- <EnableLocationBrowseButton>true</EnableLocationBrowseButton>
- <Icon>img.png</Icon>
- </TemplateData>
- <TemplateContent>
- <ProjectCollection>
- <ProjectTemplateLink ProjectName="$projectname$.Offline">
- Dev_Offline\MyTemplate.vstemplate
- </ProjectTemplateLink>
- <ProjectTemplateLink ProjectName="$projectname$.Online">
- DevEnv_Online\MyTemplate.vstemplate
- </ProjectTemplateLink>
- <ProjectTemplateLink ProjectName="$projectname$.Service">
- DevEnv_Service\MyTemplate.vstemplate
- </ProjectTemplateLink>
- <ProjectTemplateLink ProjectName="$projectname$">
- DevEnv_Template\MyTemplate.vstemplate
- </ProjectTemplateLink>
- </ProjectCollection>
- </TemplateContent>
- </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.
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.
The following solution is created as per the given project name. Now, you can start development using your solution template.
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.