Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an evaluated Custom Parameter in a VSTemplate

So I'm modifying a multi-project VS Template (Visual Studio project template), and I want to set a Custom Parameter in the root template to be used by the sub templates. However, I want to set it based on an existing parameter.

So, for example, this works fine:

<CustomParameter Name="$FaultProject$" Value="MyProject.FaultContracts"/>

The variable $FaultProject$ is replaced by MyProject.FaultContracts, as it should be.

This, however, does not work:

<CustomParameter Name="$FaultProject$" Value="$safeprojectname$.FaultContracts"/>

I expect $safeprojectname$ to be replaced by the correct value, but it is not. Instead, the variable $FaultProject$ is replaced by $safeprojectname$.FaultContracts. The $safeprojectname$ is interpreted as a literal rather than the parameter that it is.

This is in spite of the fact that in the same file, this works exactly as expected:

<ProjectTemplateLink ProjectName="$safeprojectname$.FaultContracts">WCFFaultContract\FaultContract.vstemplate</ProjectTemplateLink>

Any ideas would be helpful. I believe I might be able to write an IWizard class that would do this, but I'd rather avoid that for such a simple function, if possible.

Alternatively, if I can get a parameter that contains the value of the root template's $safeprojectname$, that would address my need as well (in the sub-templates, $safeprojectname$ is changed to the sub-project's name, not the value it had in the root template).

like image 617
Sean Worle Avatar asked Nov 09 '11 22:11

Sean Worle


People also ask

How do I import a project template into Visual Studio?

Project -> Export Template… Select Project Template. Select source Project. In the Template Options I choose to Automatically Import the template to Visual Studio.

What are Visual Studio templates?

Visual Studio templates These templates provide a starting point for users to begin creating projects, or to expand existing projects. Project templates provide the files that are required for a particular project type, include standard assembly references, and set default project properties and compiler options.


1 Answers

In a multi project template you can basically have replacement parameters only at the project level. The root template is at the solution level and you basically cannot have $safeprojectname$ in there. However you could implement IWizard interface and can have your own replacement parameters, substituted with the values you give.

like image 158
Soundararajan Avatar answered Sep 18 '22 13:09

Soundararajan