vs project templates to create and use

First, the use dotnet command to create (for .NET Core, you can create templates that contain any number of items, but will not appear in the new project template in vs)

The official document: https://docs.microsoft.com/zh-cn/dotnet/core/tools/custom-templates

  1. Copy all the items to be used as a template to create a new folder
  2. Add ./.template.config/template.json file in the new folder
  3. Edit template.json file, as follows:
    1 {
    2   "$schema": "http://json.schemastore.org/template",
    3   "author": "Travis Chau",
    4   "classifications": [ "Common", "Console" ],
    5   "identity": "AdatumCorporation.ConsoleTemplate.CSharp",
    6   "name": "Adatum Corporation Console Application",
    7   "shortName": "adatumconsole"
    8 }

     

  4. dotnet new -i: Create a template using the dotnet command in the new file folder path.
  5. New from Template Project: dotnet new <template name> -n <name to replace the template name> -o <new project path>
  6. Uninstall template: dotnet new -u <template path>


Two, vs "project" Export template (applies to multiple languages ​​can be used in the new project template in vs)

 The official document: https://docs.microsoft.com/zh-cn/visualstudio/ide/creating-project-and-item-templates?view=vs-2017

  1. Single project templates vs export:

    Project "Export template
    storage path for user templates vs New projects:% USERPROFILE% \ Documents \ Visual Studio 2017 \ Templates \ ProjectTemplates
    template configuration files (in a compressed file export templates generated): MyTemplate.vstemplate
    template parameters: HTTPS : //docs.microsoft.com/zh-cn/visualstudio/ide/template-parameters view = vs-2017?

  2. More project templates vs export:
    each item separately Export template
    to create a root project folder
    to extract to the root of all of template project folder
    root project folder MultiProjectTemplate.vstemplate files created
    MultiProjectTemplate.vstemplate content examples are as follows:
     1 <VSTemplate Version="2.0.0" Type="ProjectGroup"
     2     xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
     3   <TemplateData>
     4     <Name>Template</Name>
     5     <Description>An example of a multi-project template</Description>
     6     <Icon>__TemplateIcon.ico</Icon>
     7     <ProjectType>CSharp</ProjectType>
     8   </TemplateData>
     9   <TemplateContent>
    10     <ProjectCollection>
    11       <SolutionFolder Name="1-Presentation">
    12         <ProjectTemplateLink ProjectName="$safeprojectname$.Presentation.WebAPI" CopyParameters="true">
    13           Template.Presentation.WebAPI\MyTemplate.vstemplate
    14         </ProjectTemplateLink>
    15       </SolutionFolder>
    <16       SolutionFolder Name="2-Application">
    17         <ProjectTemplateLink ProjectName="$safeprojectname$.Application.IService" CopyParameters="true">
    18           Template.Application.IService\MyTemplate.vstemplate
    19         </ProjectTemplateLink>
    20         <ProjectTemplateLink ProjectName="$safeprojectname$.Application.Service" CopyParameters="true">
    21           Template.Application.Service\MyTemplate.vstemplate
    22         </ProjectTemplateLink>
    </23       SolutionFolder>
    24       <SolutionFolder Name="3-Domain">
    25         <ProjectTemplateLink ProjectName="$safeprojectname$.Domain.IService" CopyParameters="true">
    26           Template.Domain.IService\MyTemplate.vstemplate
    27         </ProjectTemplateLink>
    28         <ProjectTemplateLink ProjectName="$safeprojectname$.Domain.Service" CopyParameters="true">
    29           Template.Domain.Service\MyTemplate.vstemplate
    30         </ProjectTemplateLink>
    31       </SolutionFolder>
    32       <SolutionFolder Name="4-Infrastructure">
    33         <ProjectTemplateLink ProjectName="Template.Infrastructure.Show" CopyParameters="true">
    34           Template.Infrastructure.Show\MyTemplate.vstemplate
    35         </ProjectTemplateLink>
    36       </SolutionFolder>
    37     </ProjectCollection>
    38   </TemplateContent>
    39 </VSTemplate>

    Use $ ext_safeprojectname $ modify local (.csproj project file, .cs code file and .vstemplate template files) require the application root application name the template for all project documents
    last modified good place to repackaging template storage path for user templates, you can see your template vs New projects

Guess you like

Origin www.cnblogs.com/LaughAtSelfsWrong/p/11432458.html