Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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.

like image 800
Nathvi Avatar asked Oct 18 '22 22:10

Nathvi


1 Answers

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.


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


Here are just a couple of references I used:

  • MSDN article - "How to: Create Multi-Project Templates"
  • A blog post from jayway.com (March 13, 2015) - "Visual Studio: How to create a solution template with multiple projects" (this was my primary source as it includes pretty detailed instructions along with screenshots to help explain the same steps outlined in the MSDN article, as well as some additional "tips")

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)". 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.

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

At this point, my best suggestion would be to make or vote on a suggestion on the Visual Studio feedback forums. 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).

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

  • In the <VSTemplate> element, set the Type attribute to ProjectGroup instead of Project or Item (even though the MSDN documentation only lists the latter two as possible values).
  • Under the <TemplateContent> element, wrap the <ProjectCollection> element tags around the <ProjectTemplateLink> (and possibly the <Project>) elements.

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

like image 85
G_Hosa_Phat Avatar answered Oct 20 '22 23:10

G_Hosa_Phat