简体   繁体   中英

Multi project template Visual Studio 2017

I have followed How to create a multi project template in visual studio 2013? article to create a template. My Project structure is as follows : ProjectName.Domain, ProjectName.Service, ProjectName.UI, ProjectName.sln, root.vstemplate

The root.vstemplate file contains the following:

根

Within each sub project there is a ProjectName.vstemplate file, which contains something like this:

项目

I have added the *.zip file to /My Documents/Visual Studio 2017/Templates/ProjectTemplates/, but the template does not appear in the New Project Dialog box.

I had no success either in following the example, which uses Version="2.0.0" for the root vstemplate file. However, when I followed This article which has en example using Version="3.0.0" it worked.

I copied this xml from the article for quick reference:

<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>  

You can use the tool available here:

https://github.com/taori/Amusoft.VisualStudio.TemplateGenerator

and use the desktop client or the commandline tool using

build configuration [configurationName]

after setting up a configuration in the desktop client like this:

样品 you are good to go.

That way you can regularly update your template with little effort.

run devenv.exe with the /installvstemplates switch. This will force Visual Studio to update the project and item templates.

eg

"%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe" /installvstemplates

or where-ever you have installed your Visual Studio. I recommend adding your zip to one of the folders within the ProjectTemplates though, otherwise you'd make a mess of your project dialog box.


If you would want to use something like this in a bat file, here's a quick example of how to easily do that

set VSDir=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE
echo Updating templates...
START "" /B /W "%VSDir%\devenv.exe" /installvstemplates
echo All done!
pause

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM