Programmatically Accessing the PowerShell Console (Package Manager Console)

I am trying to develop a visual studio extension to automate parts of an entity structure migration process. I checked to add the migration programmatically, but, looking at the source code of the entity, a lot has been 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 can 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 
+4
source share
2 answers

There is a Nuget distribution available as Nuget that makes all Nuget features available, just get the following http://nuget.codeplex.com/ package and use it.

It also has a PackageManager ...

I think something like this might install something:

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

The best way to run a script in the package manager console is to pass a parameter to 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); 
0
source

Source: https://habr.com/ru/post/1486104/


All Articles