[英]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. 我正在尝试开发一个visual studio扩展来自动化我们的实体框架迁移过程的一部分。 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. 我检查了以编程方式添加迁移但是在查看实体框架源之后,在powershell脚本中做了很多,所以我想在包管理器控制台(nuget)上获取一个钩子并在那里发送命令并从控制台读取结果如果可能的话。
How do I access the package manager console programmatically in a visual studio extension? 如何在visual studio扩展中以编程方式访问包管理器控制台?
For example I would like to send the following command to the package manager console. 例如,我想将以下命令发送到包管理器控制台。
add-migration migration01
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);
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. 有一个Nuget发行版可以作为Nuget使用,它可以轻松获得所有Nuget功能,只需获取以下http://nuget.codeplex.com/包并使用它。
It also has a PackageManager... 它还有一个PackageManager ...
I guess something like that could install something: 我想这样的东西可以安装一些东西:
new PackageManager(
PackageRepositoryFactory.Default.CreateRepository("source"),
"path").InstallPackage("packageId")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.