简体   繁体   English

如何在多项目sln模板Visual Studio 2015中添加现有项目

[英]How to add existing project in multi project sln template Visual Studio 2015

I'm trying to make a sln template with multiple projects in them. 我正在尝试制作一个包含多个项目的sln模板。 What I can do is make multiple new projects in a template, but I can't figure out how to add a reference to existing projects in other solutions inside the template. 我可以做的是在一个模板中创建多个新项目,但是我不知道如何在模板中的其他解决方案中添加对现有项目的引用。 Any help is appreciated. 任何帮助表示赞赏。

EDIT 编辑

As another interested party, for clarification, this question is asking about Visual Studio Solution Templates and their ability (or lack thereof) to pattern solutions that contain existing standard projects. 作为另一个感兴趣的人,为澄清起见,此问题询问的是Visual Studio解决方案模板及其对包含现有标准项目的解决方案进行模式化的能力(或缺乏)。

In my case (I am unsure of what OP was working on) I am creating around 80 or so small console applications that each refer to several standard projects for data retrieval and so forth. 就我而言(我不确定OP在做什么),我正在创建大约80个左右的小型控制台应用程序,每个应用程序都引用多个标准项目进行数据检索等等。 I want to have a method by which I can choose New>Project>$MY CUSTOM TEMPLATE$ and it creates a solution with a console project, a test project, and includes 5 existing projects as well as some references to other stuff. 我想要一种方法,可以选择“新建”>“项目”>“ $ MY CUSTOM TEMPLATE $”,它可以创建一个包含控制台项目,测试项目的解决方案,并包括5个现有项目以及对其他内容的一些引用。

Saving a project template for the existing projects is not an option. 无法为现有项目保存项目模板。 All that will do is re-create the project in question. 所有要做的就是重新创建有问题的项目。 If ever the original project gets changed (and it will) the changes will not carry over to the copies. 如果原始项目被更改(并且将会更改),则更改将不会保留到副本中。

First, add all necessary projects to your solution (RC on solution -> Add new/existing project). 首先,将所有必要的项目添加到您的解决方案中(解决方案上的RC->添加新的/现有的项目)。

After that, you need to go to File -> export template. 之后,您需要转到文件->导出模板。 Then just proceed with pop-up windows, and you should be good to go. 然后继续执行弹出窗口,您应该一切顺利。

Based on my research and testing, I'm going to have to say that this is currently not possible ( creating a solution template that includes a "link" to an existing project instead of creating a copy of the existing project ). 根据我的研究和测试,我不得不说这目前是不可能的创建一个包含与现有项目的“链接”的解决方案模板,而不是创建现有项目的副本 )。

I would LOVE to be proven wrong about this, but I've gone through quite a bit of the MSDN documentation for Visual Studio templates, as well as some 3rd-party "tutorials"/blogs trying to find a way to make it happen. 我很乐意被证明是错误的这一点,但我已经通过相当多的MSDN文档的Visual Studio模板,以及一些第三方“教程”的消失/博客试图找到一种方式来做到这一点。


** UPDATE ** **更新**

I've posted a new suggestion in the Visual Studio feedback forums and could use support from any of you who are interested in improving the creation of templates in Visual Studio. 在Visual Studio反馈论坛上发布了一个新建议 ,可以使用任何有兴趣改进Visual Studio中模板创建的人的支持。


Here are just a couple of references I used: 这只是我使用的一些参考:

The closest thing I was able to find for being able to almost make it work was another MSDN article about how to add a pre-compiled assembly to a template - " Assembly Element (Visual Studio Templates) ". 我能够找到的最接近的东西几乎能够使它工作,这是MSDN上另一篇有关如何向模板添加预编译的程序集的文章-“ 程序集元素(Visual Studio模板) ”。 You might be able to use this to point to the \\Release (or \\Debug ) folder of your other project, but that could , in certain cases, result in some unexpected behavior after recompiling the other assembly. 您可能可以使用它指向其他项目的\\Release (或\\Debug )文件夹,但是在某些情况下,重新编译另一个程序集后可能会导致某些意外行为。

There were also some discussions about possibly making a NuGet package of your project, then referencing that in the template, but that still isn't exactly what I was looking for. 也有关于可能使你的项目的NuGet包,然后引用模板中的一些讨论,但仍然不正是我一直在寻找。 I didn't do too much research into this solution, but if you're interested in this method, here's a link to the Microsoft Docs article - " NuGet Packages in Visual Studio templates " 我没有对该解决方案进行过多研究,但是,如果您对此方法感兴趣,请访问Microsoft Docs文章的链接-“ Visual Studio模板中的NuGet包

At this point, my best suggestion would be to make or vote on a suggestion on the Visual Studio feedback forums . 在这一点上,我最好的建议是在Visual Studio反馈论坛上对建议进行表决或投票。 I was only able to find one suggestion on this topic posted there ( Support Solution templates that specify existing projects ), but it's already been closed by the Admins for not acquiring enough votes within its first two months (Nov. 2016 - Jan. 2017). 我只能在此处找到有关此主题的建议( 指定现有项目的支持解决方案模板 ),但是由于前两个月(2016年11月至2017年1月)未获得足够的选票,管理员已将其关闭。 。

If you post a new suggestion, I'd recommend you promote and share it with anyone you think might be interested so you can start picking up votes and keep it from getting closed. 如果您发布新的建议,我建议您推广并与您认为有兴趣的任何人分享,以便您可以开始投票并防止其被关闭。


Just for reference and in the spirit of sharing, here's the "test" template I've been working with. 仅供参考,本着共享的精神,这是我一直在使用的“测试”模板。 Maybe someone else can find a way to make it work: 也许其他人可以找到一种使它起作用的方法:

SAMPLE VSTEMPLATE 样本模板

(DOES NOT PRODUCE THE DESIRED RESULT) 不产生所需的结果)

<VSTemplate Version="3.0.0" Type="ProjectGroup" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
  <TemplateData>
    <Name>New Application Template</Name>
    <Description>Template for creating a new application</Description>
    <ProjectType>VisualBasic</ProjectType>
    <ProjectSubType></ProjectSubType>
    <SortOrder>1000</SortOrder>
    <CreateNewFolder>true</CreateNewFolder>
    <DefaultName>NewApplication</DefaultName>
    <ProvideDefaultName>true</ProvideDefaultName>
    <LocationField>Enabled</LocationField>
    <EnableLocationBrowseButton>true</EnableLocationBrowseButton>
    <Icon>SampleIcon.png</Icon>
  </TemplateData>
  <TemplateContent>
    <ProjectCollection>
        <Project File="C:\Development\Libraries\MyLibrary.vbproj">
        </Project>
        <ProjectTemplateLink ProjectName="$projectname$.UI">
                UI\MyUI.vstemplate
        </ProjectTemplateLink>
    </ProjectCollection>
  </TemplateContent>
</VSTemplate>

In my research, it appears that there are a couple of keys to making a solution template (instead of a project template): 在我的研究中,看来制作解决方案模板(而不是项目模板)有几个关键:

I've tried a number of variations and iterations of this .vstemplate file but, all I get when I try to create a new project in Visual Studio is a single project "solution" ( $projectname$.UI ). 我已经尝试过此.vstemplate文件的多种变体和迭代,但是,当我尝试在Visual Studio中创建新项目时,得到的只是一个项目“解决方案”( $ projectname $ .UI )。 I've tried moving the path/filename of the existing project down into the tag data (instead of the File property), to a <ProjectItem> sub-element of the <Project> element, and all sorts of other little "tweaks" in my attempts to get it to work. 我尝试将现有项目的路径/文件名向下移动到标签数据(而不是File属性)中,移到<Project>元素的<ProjectItem>子元素中,并进行各种其他的小“调整”在我尝试使其正常工作的过程中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为.NET Core创建Visual Studio 2015项目模板? - How to create a Visual Studio 2015 project template for NET Core? 无法在Visual Studio 2015 Web API项目中添加nuget程序包 - Can not add a nuget package in visual studio 2015 web api project 找不到Teamcity Visual Studio sln目标(项目文件夹中的项目) - Teamcity Visual Studio sln Targets not found (projects inside project folder) 如何提取visual studio项目模板图标? - How to extract visual studio project template icons? Xamarin项目在Visual Studio 2015中不可用 - Xamarin project unavailable in Visual Studio 2015 在Visual Studio 2015中引用另一个项目 - Referencing another project in Visual Studio 2015 Visual Studio模板上的项目参考 - Project Reference on Visual Studio Template 如何使用超链接将现有项目(来自Web)添加到Visual Studio中的项目中? - How to add existing items (from web) to a project in visual studio using hyperlinks? 将Visual Studio 2015项目转换为Visual Studio 2017? - Convert Visual Studio 2015 project to Visual Studio 2017? 如何让Visual Studio 2015 xproject(project.json)引用依赖项目的最高框架 - How to let a Visual Studio 2015 xproject (project.json) reference the highest framework of a depending project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM