6

I am currently developing a multi-project template. I am using the approach documented here: How to: Create Multi-Project Templates. This template will have a main web site template (modeled after the MVC 3 temaplte) and a few additional calls library templates to keep functionality separate.

Example: WebsiteProject1 lives in a folder in the template project and has all of its files and .vstemplate under that folder. ClassLibrary1 lives under another folder in the template project and also has its own .vstemplate file.

My question is, how do I set up references in the WebsiteProject1 for ClassLibrary1 so that when the project is created from the template, the references are present and resolve? Is this even possible?

Mark Holtman
  • 668
  • 6
  • 10

1 Answers1

7

I was working on a similar setup today and I found that it is indeed possible but it requires a manual adaption of the csproj file of your WebsiteProject after exporting the template. Also there's some kind of bug where there's no token replacement in the Name tag under the ProjectReference tag.

Basicly you want the csproj file to contain the following:

<ItemGroup>
    <ProjectReference Include="..\$SolutionName$.Library\$SolutionName$.Library.csproj">
        <Project>{8a8efea7-e80c-4de2-8c35-ced49a814675}</Project>
        <Name>ClassLibrary</Name>
    </ProjectReference>
</ItemGroup>

Note that I did not replace the <Name> tag value since the token replacements don't work. Luckily this doesn't seem to hinder the working of the reference.

EDIT: Using the $safeprojectname$ will refer to the project itself. If your class library has a hardcoded name this isn't really a problem but in my case I wanted a name like "NewProject.Library" I solved this by adding a CustomParameter $SolutionName$ like this in my Multi Project vstemplate file:

<CustomParameters>
  <CustomParameter Name="$SolutionName$" Value="$safeprojectname$"/>
</CustomParameters>
KyleMit
  • 30,350
  • 66
  • 462
  • 664
IvanL
  • 2,475
  • 1
  • 26
  • 39
  • Where in the Multi-Project vstemplate file did you put the `CustomParameters` block? I added it, and changed my `.proj` to use `$SolutionName$`, but I haven't gotten it to replace the parameter and it just leaves those exact characters in there. – KyleMit Oct 28 '13 at 21:51
  • 1
    @KyleMit The tag is found in my as first child. – IvanL Oct 29 '13 at 09:27
  • Huh, that's where I had it and The Visual Studio Designer gave me this [**warning**](http://i.imgur.com/H5eGQJF.png). Although the [MSDN docs](http://msdn.microsoft.com/en-us/library/ms247063.aspx) seem to agree with you. Maybe I have an issue somewhere else. – KyleMit Oct 29 '13 at 13:35
  • IvanL, I wrote up my issue into a full [question](http://stackoverflow.com/q/19662836/1366033) if you wouldn't mind checking it out. – KyleMit Oct 29 '13 at 15:42
  • If someone is using VS2013+ https://stackoverflow.com/questions/19662836/using-customparameter-with-visual-studio-multi-project-template/24043435#24043435 this helped me. – cah1r Jan 22 '19 at 12:57