0

In VS2017 I've made a C# Project Template project, that uses forms and the IWizard interface to pop up a dialog as soon as the user types a project name and hits OK. The form gathers info from the user and then sets up the new project accordingly.

I haven't really detoured from the guide mentioned in the next line, except it doesn't cover what I'd like to do.

Note to future readers: This How To Use Wizards With Project Templates guide is the only version of the page I have found that points out the need for the System and System.Drawing references. And even then it says "assemblies" when it means "references". Other duplicates of the same page have a strangely blank space at the crucial moment.

So inside IWizard's RunStarted() function, I create custom template parameters that look $like$ $this$, add them to the replacementsDictionary, and assign values to them that I retrieved from my whiz-bang pop up dialog. The wizard will then substitute appearances of those custom parameters that it finds in files of the new project (I wrote those appearances earlier), with the values I assigned to them. There are also built-in template parameters that I can use in the same way.

What I can do (source files == .cpp, project file == .vcxproj):

  • Use built-in template parameters to substitute values into my template's source files and project file.
  • Define custom template parameters inside the .vstemplate file that substitute values into my template's source files and project files.
  • Define custom template parameters inside IWizard's RunStarted() function that substitute values only into my template's source files.

What I can't do:

  • Define custom template parameters within IWizard's RunStarted() function that substitute values into my template's project file.

From what I understand, the first moment I can turn user-defined values into custom parameter values is via the RunStarted() function. This is the crux of the problem, as this is apparently too late to sub anything new into the project file. In the end product project file, all built-in template parameters get substituted as expected. All my custom template parameters that I defined in advance in the .vstemplate file are also subbed as expected. But the custom template parameters that I need to set up in RunStarted()... they still all look $like$ $this$.

In other words, if I write this inside RunStarted():

replacementsDictionary.Add("$custommessage$", "Custard");

then my source files will now have occurrences of Custard, but the project file will still only have $custommessage$.

This is forcing an XML-writing work around that is bringing its own problems, so I have come back to this. How can I get user-defined custom template parameter values into the project file?

Xenial
  • 465
  • 2
  • 15

1 Answers1

1

It's the question that is broken. Template parameters do work in the project file straight off the bat. If they aren't working, it means something is wrong somewhere else. Ie., double check all your template parameters are working, are getting values, etc. It's typically one of them going wrong that causes the grief that inspired this question.

Xenial
  • 465
  • 2
  • 15