16

I built my own project template. When a project is created with the template, a custom wizard is launched that allows the user to edit the project that was created.

The problem is that I also need to add some very simple nuget packages to the created project (just mvvmlight, MyToolkit and 1 other). To do this I added a WizardData element to my vstemplate with the right packages.

Here comes the problem: in order to launch my custom wizard, I need to put a reference to my wizard inside the WizardExtension element. But in order to install the nuget packages automatically I need to place a reference towards NuGet.VisualStudio.TemplateWizard inside my WizardExtension element, and the WizardExtension can only have one class that it will instantiate, but I have 2 that need to run.

So how do I solve this?

Here's the code that launches my own wizard. Now I just need the NuGet packages to install too:

<WizardExtension>
    <Assembly>PartyTemplateWizard, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=7eb2f41084fd4cd5</Assembly>
    <FullClassName>PartyTemplateWizard.Wizard</FullClassName>
</WizardExtension>
<WizardData>
    <packages repository="template">
        <package id="MvvmLight" version="4.1.27.0" />
        <package id="MvvmLightLibs" version="4.1.27.0" />
        <package id="MyToolkit" version="1.14.0" />
        <package id="linqtotwitter" version="2.1.06" />
    </packages>
</WizardData>

Does anyone have a solution?

Alexander
  • 2,320
  • 2
  • 25
  • 33
Leon Cullens
  • 12,276
  • 10
  • 51
  • 85

2 Answers2

9

Well, I came across the same issue and was disappointed to find no answer for this post. Now I've got the answer and I'm posting it.

There cannot be two wizard extensions. So you need to instantiate NuGet from your custom wizard (see below) and delegate all methods to this instance.

Add these lines to the RunStarted method:

Assembly asm = Assembly.Load("NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a");
wizard = (IWizard)asm.CreateInstance("NuGet.VisualStudio.TemplateWizard");

And, call the method on the instance like this:

wizard.RunStarted(automationObject, replacementsDictionary, runKind, customParams);

Similar way delegate to the wizard instance in all methods.

Alexander
  • 2,320
  • 2
  • 25
  • 33
user1759228
  • 143
  • 1
  • 8
2

Instead of trying to place multiple references in one WizardExtension element - you can add multiple WizardExtension elements (one for each assembly reference).

For example:

<WizardExtension>
  <Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
  <FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName>
</WizardExtension>

<WizardExtension>
  <Assembly>PartyTemplateWizard, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=7eb2f41084fd4cd5</Assembly>
  <FullClassName>PartyTemplateWizard.Wizard</FullClassName>
</WizardExtension>

<WizardData>
  <packages repository="extension" repositoryId="your-extension-id-here">
    <package id="MvvmLight" version="4.1.27.0" />
    <package id="MvvmLightLibs" version="4.1.27.0" />
    <package id="MyToolkit" version="1.14.0" />
    <package id="linqtotwitter" version="2.1.06" />
  </packages>
</WizardData>

References used:

Disclaimer: I have tested this on Visual-Studio-2015 only; not on Visual-Studio-2012 (although a quick look through the answers on this link seems to indicate that it is supported on VS2012 too)

Sharada Gururaj
  • 13,471
  • 1
  • 22
  • 50