I am trying to make a Visual Studio Project Template. I can easily replace the names of things I want to have the same name as the project using $safeprojectname$
So if my project was named WidgetHunter
and I named a file $safeprojectname$.js
it would be called WidgetHunter.js
when the project was created.
But what if I wanted to name the file widgetHunter.js
or widget-hunter.js
?
Is there away to make a new variable that does not have a static value? (I need to perform a string operation on the supplied project name.)
So this will not be as straight forward as you allude. Project Templating is not very powerful, it's basic replacement, you can't really run code AFAIK.
However, you can "easily" add a Wizard Step (IWizard
) that adds additional keys to the replacement dictionary. For example, you could add $safeprojectnameforjs$
which has the manipulated value.
public class ExampleWizard : IWizard
{
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
replacementsDictionary.Add("safeprojectnameforjs",
YourCustomMethodForManipulatingName(replacementsDictionary["safeprojectname"])
}
// there are a few other IWizard methods you'll need to
// implement but don't need to do anything in
}
To wire in your ExampleWizard, you'll need to add a tag in your .vstemplate
<VSTemplate>
<WizardExtension>
<Assembly>ExampleWizard.ExampleWizard, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=a76e3e75702e3ee4</Assembly>
<FullClassName>ExampleWizard.ExampleWizard</FullClassName>
</WizardExtension>
</VSTemplate>
Note: You'll need to have your Wizard in an assembly. Easiest way is to create a new Class Library project. Also, it will need to be signed (at least, pretty sure that's still a requirement).
Finally, you'll need to update your VSIX manifest, so that you have the Wizard assembly wired up as an assembly dependency:
<PackageManifest>
<Assets>
<Asset Type="Microsoft.VisualStudio.Assembly" d:Source="Project" d:ProjectName="ExampleWizard.ExampleWizard" Path="|ExampleWizard.ExampleWizard|" AssemblyName="|ExampleWizard.ExampleWizard;AssemblyName|" />
</Assets>
</PackageManifest>