多项目/解决方案模板为Visual Studio 2012与VSIX安装程序和软件包的NuGet [英] Multi Project / Solution Templates for Visual Studio 2012 with VSIX Installer and Nuget Packages

查看:853
本文介绍了多项目/解决方案模板为Visual Studio 2012与VSIX安装程序和软件包的NuGet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个多项目模板,将创建分项目,将安装的NuGet依赖,以及有一个VSIX安装程序,安装此模板。



与方法已经试过



不VSIX 多项目模板,没有的NuGet



问题

我能够创建一个多项目模板,它工作得很好,除非是时候包括的NuGet引用,它没有工作。有人支持的NuGet不涉及VSIX不容易/优雅的支持。



多项目模板与VSIX,无根模板



所以,我尝试使用VSIX,似乎非常简单。添加模板项目作为ZIP或解决方案,构建VSIX安装程序。但是,当我添加第二个项目模板,建立一个多项目模板,建造它,安装模板,并试图创建一个项目,我意识到,它不支持主 - 分项目设置,其中主项目创建子项目。这是一个大问题,因为开发商将不得不创建依赖顺序每个项目。


解决方案

我终于有工作设置。我花了试验和拼凑不同的MSDN文章和博客的许多天摸不着头脑。



合并多项目模板(带根模板)和VSIX



结束结果是




  • 的Visual Studio 2012 VSIX项目,其中包含一个包文件夹的
    拥有所有的Nu​​Get依赖关系。

  • 与根/主模板的ZIP文件,该文件的多个
    项目链接起来也都在压缩文件中的
    对应的文件夹中。

  • 内置VSIX安装程序将安装一个单独的项目模板
    有子项目。

  • 这将让你保持从
    A项目的模板不断发展壮大,用很少的努力,使用文件导出
    模板功能。

  • 使用自动生成的,可自定义的参数,以您的
    模板命名空间和文件重命名为匹配新的项目名称。



在创建这个模板的项目,它会自动创建多个子项目,然而,子项目并不(但可以)作为新项目的菜单自己的模板。这是伟大的,如果你想模板类似的企业设计,是依赖于合作许多项目,但你不希望用户能够创建这些子工程,或者你希望他们在不同的可。项目模板面积/类别



步骤:






  1. 创建一个文件夹MyTemplate的

  2. 创建一个root.vstemplate文件

  3. 添加以下文件:



    <预类=郎咸平的XML prettyprint-覆盖> < WizardExtension>
    <大会> NuGet.VisualStudio.Interop,版本= 1.0.0.0,文化=中性公钥= b03f5f7f11d50a3a< /组装>
    < FullClassName> NuGet.VisualStudio.TemplateWizard< / FullClassName>
    < / WizardExtension>
    < WizardData>
    <软件包库=扩展名repositoryId =填补了这一在>
    <包ID =Newtonsoft.Json版本=5.0.6/>
    < /包>
    < / WizardData>


  4. 打开你的第一个项目,你想作为一个子项目模板,导出模板使用从文件 - >导出模板。


  5. 将压缩内容到你的文件夹MyTemplate的,所以你最终MyTemplate的/ PROJECT1

  6. 从您刚提取什么打开Project1.vstemplate。

  7. 和在TemplateContent块下方粘贴以下内容(例如,如果你想添加一个JSON的NuGet包)



    <预类=郎咸平的XML prettyprint-覆盖> < WizardExtension>
    <大会> NuGet.VisualStudio.Interop,版本= 1.0.0.0,文化=中性公钥= b03f5f7f11d50a3a< /组装>
    < FullClassName> NuGet.VisualStudio.TemplateWizard< / FullClassName>
    < / WizardExtension>
    < WizardData>
    <软件包库=扩展名repositoryId =填补了这一在>
    <包ID =Newtonsoft.Json版本=5.0.6/>
    < /包>
    < / WizardData>


  8. 拉上你的整个根文件夹MyTemplate的,所以你最终MyTemplate.zip有该MyTemplate的文件夹中的内容。


  9. 创建一个VSIX项目(你需要的Visual Studio 2012 SDK有这个模板)从在C#的扩展模板类别。

  10. 创建一个包文件夹

  11. 添加的NuGet包(.nupkg文件只),你在你的子项目引用vstemplate到软件包文件夹和文件的属性,其设置生成操作的内容,并在VSIX包括为true。以我为例,我添加Newtonsoft.Json.5.0.6.nupkg。

  12. 在source.extension.vsixmanifest设置作者姓名

  13. 在资产标签,从下拉菜单中点击新建,然后选择项目模板下来,然后在接下来的下拉文件系统上的文件。

  14. 浏览并选择您创建的ZIP,点击OK。这将创建一个文件夹ProjectTemplates用拉链。

  15. 产品ID从source.extension.vsixmanifest的顶级副本。

  16. 打开了拉链像WinRAR的一个程序,让您可以直接更改保存到ZIP(默认的Windows压缩应用程序不允许这样)。

  17. 粘贴在产品ID进入repositoryid栏目

  18. 将更改保存到zip文件(请确保你回去WinRAR的,如果这是你使用的是什么,因为它会检测更改,会询问你是否要更新)

  19. 生成解决方案,并进入到bin / debug文件夹运行VSIX安装程序

  20. 创建项目



可选步骤让你的主项目重命名文件和命名空间




  • 开启每个分项目vstemplate文件,并添加$ safeprojectname $到defaultName中元素。例如



<预类=郎咸平的XML prettyprint-覆盖> < defaultName中> $ safeprojectname $。域< / defaultName中>


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.

Problems with methods already tried

Multi project template without VSIX, no 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. There was no easy/elegant support for nuget that did not involve VSIX.

Multi project template with VSIX, without a root template

So I tried using VSIX, and it seemed very straightforward. Add a template project as a zip or from solution, build the vsix installer. 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. 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.

Combining Multi project template (with root template) and VSIX

The end result is

  • Visual Studio 2012 VSIX project, which holds a packages folder that has all the nuget dependencies.
  • A Zip file with the root/master template which links the multiple projects together that are also in the zip file in their corresponding folders.
  • A built vsix installer which will install a single project template that has sub projects.
  • This will allow you to maintain a template from a project that continues to grow, with very little effort, using the File-Export Template feature.
  • Uses auto generated and customizable parameters to rename your template namespaces and files to match your new project name.

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:

  1. Create a folder "MyTemplate"
  2. Create a root.vstemplate file
  3. 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>
    

  4. Open your first project you wish to use as a "sub project" template, export template from File->Export Template.

  5. Extract the zip contents to your MyTemplate folder, so you end up with MyTemplate/Project1
  6. Open up the Project1.vstemplate from what you just extracted.
  7. and paste in the following below the TemplateContent block (for example if you want to add a Json nuget package)

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

  8. Zip up your entire root folder MyTemplate, so you end up with MyTemplate.zip which has the contents of the MyTemplate folder.

  9. Create a VSIX project (you will need Visual Studio 2012 SDK to have this template) from the Extensibility template category under C#.
  10. Create a packages folder
  11. Add the nuget package (.nupkg file only) you referenced in your sub projects vstemplate to the packages folder and in the files properties, set its build action to content, and Include in VSIX to true. In my case I added Newtonsoft.Json.5.0.6.nupkg.
  12. In the source.extension.vsixmanifest set the Author name
  13. In the Assets tab, click new and select project template from the drop down, then file on file-system in the next drop down.
  14. Browse and select the zip you created, hit Ok. This will create a ProjectTemplates Folder with the zip.
  15. Copy the Product Id from the top of the source.extension.vsixmanifest.
  16. Open up the zip with a program like WinRar that allows you to save changes directly to the zip (the default windows zip app does not allow this).
  17. Paste in the Product id into the repositoryid section
  18. Save the changes to the zip file (make sure you go back to WinRar if thats what you are using, as it will have detected the changes and will ask you if you wish to update)
  19. Build the solution and go to the bin/debug folder to run the vsix installer
  20. Create your project

Optional Step to have your master project rename your files and namespaces

  • Open each sub project vstemplate file, and add $safeprojectname$ to the DefaultName Element. e.g.

<DefaultName>$safeprojectname$.Domain</DefaultName>

这篇关于多项目/解决方案模板为Visual Studio 2012与VSIX安装程序和软件包的NuGet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆