Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add nuget packages and run custom project wizard?

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?

like image 563
Leon Cullens Avatar asked Jul 07 '13 02:07

Leon Cullens


People also ask

How do I add NuGet package source to Visual Studio?

In Visual Studio, select Tools, and then select Options. Select NuGet Package Manager, and then select Package Sources. Enter the feed's Name and Source URL, and then select the green (+) sign to add a new package source.

How do I use a Nupkg file?

Copy the . nupkg file to a local folder. Add the folder to your package sources using the nuget sources add -name <name> -source <path> command (see nuget sources). Note that you need only set this local source once on any given computer.


1 Answers

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.

like image 54
user1759228 Avatar answered Sep 18 '22 09:09

user1759228