[英]Multi Project / Solution Templates for Visual Studio 2012 with VSIX Installer and Nuget Packages
I would like to have a multi-project template that will create sub projects, and will install the nuget dependencies as well as have a vsix installer that will install this template. 我想有一个多项目模板,它将创建子项目,并将安装nuget依赖项以及安装此模板的vsix安装程序。
Problems with methods already tried 方法问题已经尝试过
Multi project template without VSIX, no nuget 没有VSIX的多项目模板,没有nuget
I was able to create a multi project template, and it worked fine, except when it came time to including nuget references, it did not work. 我能够创建一个多项目模板,它工作正常,除非是时候包括nuget引用,它不起作用。 There was no easy/elegant support for nuget that did not involve VSIX. 对于没有涉及VSIX的nuget,没有简单/优雅的支持。
Multi project template with VSIX, without a root template 具有VSIX的多项目模板,没有根模板
So I tried using VSIX, and it seemed very straightforward. 所以我尝试使用VSIX,看起来非常简单。 Add a template project as a zip or from solution, build the vsix installer. 将模板项目添加为zip或解决方案,构建vsix安装程序。 But when I added the second project template, to create a multi project template, built it, installed the template and tried to create a project I realised that it does not support a master-sub project setup, where a master project creates sub projects. 但是当我添加第二个项目模板,创建一个多项目模板,构建它,安装模板并尝试创建一个项目时,我意识到它不支持master-sub项目设置,其中一个主项目创建子项目。 This was a big problem because developers would have to create each project in dependency order. 这是一个很大的问题,因为开发人员必须按依赖顺序创建每个项目。
I finally have the setup working. 我终于让设置工作了。 It took me many days of experimenting and patching together different MSDN articles and blogs to figure this out. 我花了很多天的时间尝试和修补不同的MSDN文章和博客来解决这个问题。
Combining Multi project template (with root template) and VSIX 结合多项目模板(与根模板)和VSIX
The end result is 最终的结果是
When creating a project with this template, it automatically creates multiple sub-projects, yet, the sub-projects are not (but can be) available as templates in the new project menu themselves. 使用此模板创建项目时,它会自动创建多个子项目,但子项目不是(但可以)作为新项目菜单中的模板。 This is great if you are trying to template something like an enterprise design that is dependent on many projects working together, but you don't want the user to be able to create these sub projects, or you want them to be available in a different project template area/category. 如果您尝试模拟依赖于许多项目一起工作的企业设计,但是您不希望用户能够创建这些子项目,或者您希望它们可以在不同的项目中使用,那么这非常有用。项目模板区域/类别。
Steps: 脚步:
Add the following to the file: 将以下内容添加到文件中:
<WizardExtension> <Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly> <FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName> </WizardExtension> <WizardData> <packages repository="extension" repositoryId="fill this in"> <package id="Newtonsoft.Json" version="5.0.6" /> </packages> </WizardData>
Open your first project you wish to use as a “sub project” template, export template from File->Export Template. 打开您希望用作“子项目”模板的第一个项目,从文件 - >导出模板导出模板。
and paste in the following below the TemplateContent block (for example if you want to add a Json nuget package) 并在下面的TemplateContent块中粘贴(例如,如果你想添加一个Json nuget包)
<WizardExtension> <Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly> <FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName> </WizardExtension> <WizardData> <packages repository="extension" repositoryId="fill this in"> <package id="Newtonsoft.Json" version="5.0.6" /> </packages> </WizardData>
Zip up your entire root folder MyTemplate, so you end up with MyTemplate.zip which has the contents of the MyTemplate folder. 压缩整个根文件夹MyTemplate,最终得到MyTemplate.zip,其中包含MyTemplate文件夹的内容。
Optional Step to have your master project rename your files and namespaces 可选步骤让您的主项目重命名您的文件和名称空间
<DefaultName>$safeprojectname$.Domain</DefaultName>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.