2017年10月21日 星期六

[Visual Studio] Create solution template

 Visual Studio    Project template   Solution template


Introduction


A sample for creating a solution template with multiple project templates.


Related articles



Environment


Visual Studio 2017 community



Samples


I created a sample solution like this,





Export needed projects






And that will create two zip files.




Project template

Now extract the zip files and just keep the extracted folders as following.




You can still edit the template metadata in MyTemplate.vstemplate for each project template.






Create solution level .vstemplate

Create an xml file named Root.vstemplate

$ copy nul> Root.vstemplate


PS. Icon is optional.



Root.vstemplate

<VSTemplate Version="3.0.0" Type="ProjectGroup" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
  <TemplateData>
    <Name>JB's Template</Name>
    <Description>A Solution Template sample</Description>
    <ProjectType>CSharp</ProjectType>
    <ProjectSubType>
    </ProjectSubType>
    <SortOrder>1000</SortOrder>
    <CreateNewFolder>true</CreateNewFolder>
    <DefaultName>JB.AspnetCore</DefaultName>
    <ProvideDefaultName>true</ProvideDefaultName>
    <LocationField>Enabled</LocationField>
    <EnableLocationBrowseButton>true</EnableLocationBrowseButton>
    <Icon>favicon.ico</Icon>
  </TemplateData>
  <TemplateContent>
    <ProjectCollection>
      <ProjectTemplateLink ProjectName="$projectname$.AspnetCore.Website">
        JB.AspnetCore.Website\MyTemplate.vstemplate
      </ProjectTemplateLink>
      <ProjectTemplateLink ProjectName="$projectname$.AspnetCore.Service">
        JB.AspnetCore.Website\MyTemplate.vstemplate
      </ProjectTemplateLink>
    </ProjectCollection>
  </TemplateContent>
</VSTemplate>


Pack the solution template

Compress all the project template folders, icon and Root.vstemplate to a zip file.



Copy it to ~\Documents\Visual Studio {version}\Templates\ProjectTemplates

And now we can create a visual studio solution with this solution template.







Reference


沒有留言:

張貼留言