Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS 2010 Multi-Project Template: Inter-Project References

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?

like image 555
Mark Holtman Avatar asked Mar 29 '12 13:03

Mark Holtman


1 Answers

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>
like image 172
IvanL Avatar answered Oct 23 '22 07:10

IvanL