Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When creating a multiple project template for visual studio is there a way to use parameters in the root template file?

I am trying to create a multi project template. I wish the sub projects names to contain the solution name. I have tried the following however $safeprojectName$ doesn't work in the root template for some reason. It tries to create the folders with $safeprojectName$ in the name rather than the actual project name.

<VSTemplate Version="2.0.0" Type="ProjectGroup"
  xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
  <TemplateData>
    <Name>Default Solution</Name>
    <Description>An example of a multi-project template</Description>
    <Icon>Icon.ico</Icon>
    <ProjectType>CSharp</ProjectType>
  </TemplateData>
  <TemplateContent>
    <ProjectCollection>
      <SolutionFolder Name="$safeprojectName$.Web">
        <ProjectTemplateLink ProjectName="$safeprojectName$.Web">
          Src\Web\MyTemplate.vstemplate
        </ProjectTemplateLink>
      </SolutionFolder>
    </ProjectCollection>
  </TemplateContent>
</VSTemplate>

I have done a lot of reading on this and have and have created an assembly using the IWizard interface that creates a parameter $solutionName$. I then used the following template.

<VSTemplate Version="2.0.0" Type="ProjectGroup"
  xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
  <TemplateData>
    <Name>Default Solution</Name>
    <Description>An example of a multi-project template</Description>
    <Icon>Icon.ico</Icon>
    <ProjectType>CSharp</ProjectType>
  </TemplateData>
  <TemplateContent>
    <ProjectCollection>
      <SolutionFolder Name="$solutionName$.Web">
        <ProjectTemplateLink ProjectName="$solutionName$.Web">
          Src\Web\MyTemplate.vstemplate
        </ProjectTemplateLink>
      </SolutionFolder>
    </ProjectCollection>
  </TemplateContent>
  <WizardExtension>
    <Assembly>DefaultSoloutionWizard, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=f753ddb61a28cb36, processorArchitecture=MSIL</Assembly>
    <FullClassName>DefaultSoloutionWizard.WizardImplementation</FullClassName>
  </WizardExtension>
</VSTemplate>

This however also fails with the same problem. I'm I trying to do the impossible? Any help on this would be most welcome.

like image 853
Magpie Avatar asked Jun 29 '09 16:06

Magpie


2 Answers

As of Visual Studio 2013 Update 2 you can now use the CopyParameters attribute on the ProjectTemplateLink element in the root .vstemplate file. Any parameters defined in the root template will be available in the linked templates with a "ext_" prefix.

For example, if the root template defines a parameter, $Foo$, then the parameter $ext_Foo$ will be available in the linked projects with the same value.

See http://msdn.microsoft.com/en-us/library/ms171398.aspx for more detail.

like image 126
Andrew Cooper Avatar answered Nov 03 '22 02:11

Andrew Cooper


You may want to look into the Guidance Automation Toolkit. There's a fair amount to digest there, but part of what it can do is put a Wizard-based UI on a multi-project template.

If you want to see an example of that, take a look at the Service Factory, which can create an entire solution structure based in part on a wizard.

like image 29
John Saunders Avatar answered Nov 03 '22 02:11

John Saunders