Getting Started With The Custom Project Template Using Visual Studio 2017

Introduction

Visual Studio provides many inbuilt templates for creating a project. In this article we can create a new project template as per your client or product requirement and use your project template on multiple developers. Visual Studio provides wizards to help you generate templates from projects that are open in the integrated development environment (IDE).

Project template will allow a developer to create new projects based on your exported project. The developer will be able to utilize your template for the new project dialog box

Visual Studio

Create New Project

Let's start with creating a new UWP or any Project using visual studio 2017.

Open Run > Type Devenev.Exe and press Enter > New Project (Ctrl+Shift+N) -> Select any project Template and customize the project as per your requirement.

Visual Studio

Click on Ok and edit the project until it is ready to be exported as a template.

Export Project Template

In this article, we are exporting only one project. If you have more than one project in your current solution, I will explain in my next article.

Edit the project as per your requirement > Select the project menu from Visual Studio > Select on Export Template.

Visual Studio

Choose template Type

Choose the project template and select your project and click on Next

Visual Studio

Export Template Wizard

Fill out the template options as you want and click on Finish

  • Provide Template Name is Project template display name .
  • Provide Template Description is a detailed description about your template
  • Provide Icon Image and icon image will display near to the project Template name
  • Provide preview image and preview image will display near to describe.
  • Check the checkbox for auto import the template into visual studio or after export, will generate zip file and you can move the zip file to following location C:\Users\DevEnvExe\Documents\Visual Studio 2017\My Exported Templates

    Visual Studio

Edit Template

The file explorer should pop up with My Exported Templates where your newly exported project is packed into a .zip file.

Visual Studio
You can extract the template and if you want to edit the template, edit form MyTemplate.vstemplate file .

  1. <VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">  
  2.   <TemplateData>  
  3.     <Name>csharpcornerProjectTemplate</Name>  
  4.     <Description>csharpcornerProjectTemplate</Description>  
  5.     <ProjectType>CSharp</ProjectType>  
  6.     <ProjectSubType>  
  7.     </ProjectSubType>  
  8.     <SortOrder>1000</SortOrder>  
  9.     <CreateNewFolder>true</CreateNewFolder>  
  10.     <DefaultName>csharpcornerProjectTemplate</DefaultName>  
  11.     <ProvideDefaultName>true</ProvideDefaultName>  
  12.     <LocationField>Enabled</LocationField>  
  13.     <EnableLocationBrowseButton>true</EnableLocationBrowseButton>  
  14.     <Icon>__TemplateIcon.png</Icon>  
  15.     <PreviewImage>__PreviewImage.png</PreviewImage>  
  16.   </TemplateData>  
  17.   <TemplateContent>  
  18.     <Project TargetFileName="csharpcornerProjectTemplate.csproj" File="csharpcornerProjectTemplate.csproj" ReplaceParameters="true">  
  19.       <ProjectItem ReplaceParameters="true" TargetFileName="App.xaml">App.xaml</ProjectItem>  
  20.       <ProjectItem ReplaceParameters="true" TargetFileName="App.xaml.cs">App.xaml.cs</ProjectItem>  
  21.       <Folder Name="Assets" TargetFolderName="Assets">  
  22.         <ProjectItem ReplaceParameters="false" TargetFileName="LockScreenLogo.scale-200.png">LockScreenLogo.scale-200.png</ProjectItem>  
  23.         <ProjectItem ReplaceParameters="false" TargetFileName="SplashScreen.scale-200.png">SplashScreen.scale-200.png</ProjectItem>  
  24.         <ProjectItem ReplaceParameters="false" TargetFileName="Square150x150Logo.scale-200.png">Square150x150Logo.scale-200.png</ProjectItem>  
  25.         <ProjectItem ReplaceParameters="false" TargetFileName="Square44x44Logo.scale-200.png">Square44x44Logo.scale-200.png</ProjectItem>  
  26.         <ProjectItem ReplaceParameters="false" TargetFileName="Square44x44Logo.targetsize-24_altform-unplated.png">Square44x44Logo.targetsize-24_altform-unplated.png</ProjectItem>  
  27.         <ProjectItem ReplaceParameters="false" TargetFileName="StoreLogo.png">StoreLogo.png</ProjectItem>  
  28.         <ProjectItem ReplaceParameters="false" TargetFileName="Wide310x150Logo.scale-200.png">Wide310x150Logo.scale-200.png</ProjectItem>  
  29.       </Folder>  
  30.       <ProjectItem ReplaceParameters="false" TargetFileName="csharpcornerProjectTemplate_TemporaryKey.pfx">csharpcornerProjectTemplate_TemporaryKey.pfx</ProjectItem>  
  31.       <ProjectItem ReplaceParameters="true" TargetFileName="MainPage.xaml">MainPage.xaml</ProjectItem>  
  32.       <ProjectItem ReplaceParameters="true" TargetFileName="MainPage.xaml.cs">MainPage.xaml.cs</ProjectItem>  
  33.       <ProjectItem ReplaceParameters="false" TargetFileName="Package.appxmanifest">Package.appxmanifest</ProjectItem>  
  34.       <Folder Name="Properties" TargetFolderName="Properties">  
  35.         <ProjectItem ReplaceParameters="true" TargetFileName="AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>  
  36.         <ProjectItem ReplaceParameters="true" TargetFileName="Default.rd.xml">Default.rd.xml</ProjectItem>  
  37.       </Folder>  
  38.     </Project>  
  39.   </TemplateContent>  
  40. </VSTemplate>  
Custom Visual Studio template

 

You can now restart Visual studio and go to New Project in Visual Studio and find the Project template like below

Visual Studio

After clicking on Ok , project will automatically create new project with your default functionality .

Visual Studio

Summary

In this article, you learned how to create a project template using visual studio

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

Up Next
    Ebook Download
    View all
    Learn
    View all