Yepeekai
Yepeekai

Reputation: 2723

Access the powershell console (package manager console) of visual studio programmatically in an extension

I am trying to develop a visual studio extension to automate parts of our entity framework migration process. I checked to add migration programmatically but after looking at entity framework source, a lot is done in powershell scripts, so I would like to get a hook on the package manager console (nuget) and send a command there and read the result from the console if possible.

How do I access the package manager console programmatically in a visual studio extension?

For example I would like to send the following command to the package manager console.

add-migration migration01

Upvotes: 4

Views: 2149

Answers (2)

Ali.Asadi
Ali.Asadi

Reputation: 809

The best way for running a script in package manager console is parameter passing into it.

EnvDTE.DTE _ObjDTE;
_ObjDTE = (DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");
var script = "function global:SaveAll {write-host \"All files saved.\"} SaveAll";
_ObjDTE.ExecuteCommand("View.PackageManagerConsole", script);

Upvotes: 2

MichaC
MichaC

Reputation: 13380

There is a Nuget distribution available as Nuget which makes all Nuget functionality easily available, simply get the following http://nuget.codeplex.com/ package and use it.

It also has a PackageManager...

I guess something like that could install something:

 new PackageManager(
    PackageRepositoryFactory.Default.CreateRepository("source"), 
    "path").InstallPackage("packageId")

Upvotes: 0

Related Questions