简体   繁体   English

在扩展中以编程方式访问visual studio的powershell控制台(包管理器控制台)

[英]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.

相关问题 Package Manager Console Visual Studio 2019 返回新行 - Package Manager Console Visual Studio 2019 Returns New Line 在 Visual Studio 中使用 DTE 的包管理器控制台自动化 - Package Manager Console Automation using DTE in Visual Studio 从visual studio命令提示符运行nuget包管理器控制台 - Run nuget package manager console from visual studio command prompt 在 Visual Studio 中为 ASP.NET MVC 使用 package 管理器控制台安装 Package 时面临问题 - Facing issue while installing Package using package Manager console in Visual Studio for ASP.NET MVC 如何从Visual Studio中的包管理器控制台调用针对SQL Azure的update-database? - How to call update-database from package manager console in Visual Studio against SQL Azure? Visual Studio Pro s2017 中的 Package 管理器控制台启用-迁移 CommandNotFoundException - Package Manager Console Enable-Migrations CommandNotFoundException in visual studio pro s2017 当我在 package 管理器控制台中的 Visual Studio 2013 中安装实体框架时 - When I am installing Entity Framework in Visual Studio 2013 in the package manager console 在Visual Studio中的程序包管理器控制台上执行“更新数据库”时,出现错误:找不到内容根文件夹 - When doing an “update-database” on the package manager console in visual studio i get error : Could not find content root folder 如何使用NuGet软件包管理器控制台在Visual Studio 2012 Pro上安装OpenPop.NET? - How can i install OpenPop.NET on my visual studio 2012 pro using the NuGet package manager console? 如何在 ubuntu 18.04.2 上访问 nuget 包管理器控制台 - How can I access the nuget package manager console on ubuntu 18.04.2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM