4

I have a multi-project template that is working for the most part.

I am able to generate both projects and their files (named correctly), but one of my projects requires references to the other. I am attempting to have the template fill in these references correctly, but am having issues.

Here is my master (solution) template file:

<VSTemplate Version="2.0.0" Type="ProjectGroup"
    xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
    <TemplateData>
        <Name>Template</Name>
        <Description>Template (includes web and core)</Description>
        <Icon>Icon.ico</Icon>
        <ProjectType>CSharp</ProjectType>
    </TemplateData>
    <TemplateContent>
        <ProjectCollection>
            <ProjectTemplateLink ProjectName="$safeprojectname$.Web">
                Template.Project.Web\MyTemplate.vstemplate
            </ProjectTemplateLink>
            <ProjectTemplateLink ProjectName="$safeprojectname$.Core">
                Template.Project.Core\MyTemplate.vstemplate
            </ProjectTemplateLink>
        </ProjectCollection>
    </TemplateContent>
</VSTemplate>

Now inside the ".Web" project, I often say using x.Core;, but if I do $safreprojectname$.Core the line ends up being x.Web.Core. It seems that once each project is being generated, the $safreprojectname$ variable is changed to the current project. Which makes sense. But is there a way to either get the solution name or perhaps the name of other projects? I tried setting a variable in the solution file, but it does not seem to be passed to the project files.

Anyone have a suggestion?

Edit: in addition to the helpful answer below, here is a blog that I wrote after I finished this process. It links to a bunch of articles that I found to be very helpful: https://thebhwgroup.com/blog/2013/10/visual-studio-templates

PFranchise
  • 6,642
  • 11
  • 56
  • 73

2 Answers2

2

I ended up solving this problem with the use of a wizard as shown in the following example: http://blog.tonysneed.com/2011/09/14/build-a-multi-project-visual-studio-template/

In addition to the blog above, check out the top comment below for VS 2013. I also wrote a quick blog that helps with older versions of VS: https://thebhwgroup.com/blog/2013/10/visual-studio-templates

PFranchise
  • 6,642
  • 11
  • 56
  • 73
  • 2
    The question is for VS 2010 but for anyone with VS 2013 Update 2 and later who landed here, there's a solution [here](http://stackoverflow.com/a/24043435/2530736) on a similar question. It involves the `CopyParameters` attribute on `ProjectTemplateLink` – Vanlalhriata Apr 27 '15 at 12:42
0

This is Q old, I tried doing this in VS 2019.

Another way to do this is to set CopyParameters="true" on each project link in your parent template as below

<ProjectTemplateLink CopyParameters="true" ProjectName="$projectname$.API">

this allows you get the original value for $projectname$ that would get set above in your parent template by using $ext_projectname$

example snippet in a .proj file:

<ItemGroup>
    <ProjectReference Include="..\$ext_projectname$.BL\$ext_projectname$.BL.csproj" />
    <ProjectReference Include="..\$ext_projectname$.DTO\$ext_projectname$.DTO.csproj" />
</ItemGroup>

you would have to do this in all your required usings.

Edit: Just saw the comment from Vanlalhriata in the answer here

David
  • 5,403
  • 15
  • 42
  • 72