问题
I'm trying to get these parameters while creating a visual studio template but it doesn't return a value, it just stays like this:
string rootnamespace = $rootnamespace$; // this is the output, it just stays as it was declared
string SpecificSolutionName = $SpecificSolutionName$; // this is the output, it just stays as it was declared
According to msdn - Template Parameters:
SpecificSolutionName: The name of the solution. When "create solution directory" is checked, SpecificSolutionName has the solution name. When "create solution directory" is not checked, SpecificSolutionName is blank.
And I made sure that the "create solution directory" is checked, but still it doesn't give any value.
How can I get these values. please... ?
回答1:
I also found $SpecificSolutionName$ to be broken. As a work around it turns out the directory of the solution is usually the same as the name of the solution and thus:
If your solution template has only 1 project: the solution and project names are identical and thus you can simply use $projectname$ in lieu of the broken $SpecificSolutionName$.
If your solution template has multiple projects (aka ProjectCollection): add the attribute CopyParameters="true" to the desired ProjectTemplateLink element and use $ext_projectname$ in lieu of the broken $SpecificSolutionName$.
回答2:
I think the documentation is not enough clear when it comes to multiproject templates. Putting the wizard declaration in the vstemplate of your multiproject definition, and on the project/s that you desired to use to, makes the "broken" variable appears.
This is because, it launch the wizard for each time you declare it, so to speak, and it behaves differently depending on the context.
Pay attention: the variable $SpecificSolutionName$
only has value when executing the first time for the multiproject vstemplate declaration, and only executes RunStarted
, ProjectFinishedGenerating
and RunFinished
methods. So, to use it in a global context you need to figure out some kind of mechanism to mantain the value between Wizard executions, as adding a new key in the replacementsDictionary
or something.
Hope this help.
回答3:
I fixed this by adding this doctype declaration to the start of my .vstemplate.
<?xml version="1.0" encoding="utf-8"?>
The doctype declaration is not supplied by the template wizard, but is present in all the preinstalled templates. Good luck and thank you for your patience while I researched this question.
回答4:
$SpecificSolutionName$ is always empty. How can I tell if the user is making a new solution directory or not?
Frustratingly, the docs are wrong in 2 ways.
There is no "SpecificSolutionName". It is "SpecifiedSolutionName".
If the user unticks "Create directory for solution", then $SpecifiedSolutionName$ is not blank as stated; it actually becomes the same as $projectname$. How you determine when this has or has not occurred and whether what you're reading is a unique solution folder's name or not, is another story.
来源:https://stackoverflow.com/questions/29732550/visual-stuio-template-parameters-not-returning-values