How to create an evaluated Custom Parameter in a VSTemplate
Asked Answered
E

1

11

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).

Evacuation answered 9/11, 2011 at 22:40 Comment(2)
Did you ever figure out how to resolve this issue?Throes
No, I never did find a good answer. It looks like, as I was afraid above, I will have to write an IWizard interface. I will have to get back to it later, as project deadlines have meant that just editing the project and solution files manually is faster than writing the IWizard solution. I want to eventually, as this will come up again (the whole point of templates in the first place). I wish there was a solution that would address this without requiring my team to have an additional piece of custom code on all their machines in order to work, but that's what I'm left with.Evacuation
R
1

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.

Rarotonga answered 21/5, 2012 at 21:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.