从 powershell 获取正在运行的 Visual Studio 实例 (DTE) 的句柄 [英] Get a handle on the running Visual Studio instance (DTE) from powershell

查看:50
本文介绍了从 powershell 获取正在运行的 Visual Studio 实例 (DTE) 的句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取当前正在运行的 Visual Studio 实例的实例?我需要在 Visual Studio 之外访问 Visual Studio 对象模型 (DTE).

How do I get an instance of a currently running Visual Studio instance ? I need to access Visual Studio object model (DTE) outside of the Visual Studio.

我想从 powershell ise 运行一个 nuget 安装脚本 - 以便能够更好地了解脚本在做什么以及为什么它没有按照我的预期运行

I want to run a nuget install script from powershell ise - to be able to better understand what the script is doing and why it's not doing what i expect

所以我想输入 install.ps1 接受的所有参数

So I want to feed in all the parameters that install.ps1 takes in

param(
    [Parameter(Mandatory=$true)] [string]   $installPath,
    [Parameter(Mandatory=$true)] [string]   $toolsPath,
    [Parameter(Mandatory=$true)]            $package,
    [Parameter(Mandatory=$true)]            $project
)

设置字符串参数很简单,gowever

It's easy to set the strings parameters, gowever

项目和包是棘手的

我确实可以访问 nuget cmdlet.我按照 这篇 帖子来实现这一目标.

I do have access to nuget cmdlets. I followed this post to achieve that.

所以我导入模块 PackageManagement.Cmdlets.dll

So I import-module PackageManagement.Cmdlets.dll

一切正常

现在当我尝试类似

$project = Get-Project -name SmartCom.Registration.Logic

我收到此消息必须打开项目才能运行此命令."所以我想我首先需要通过 DTE 连接到 vs 并打开一个解决方案,然后加载一个项目才能使其正常工作?

I get this message "A project must be open to run this command." so I guess I first need to hook into vs via DTE and open a solution and then load a project in order for this to work?

我知道 PowerConsole 之类的东西可以自动与 vs 连接,但在这种情况下,我希望它在 vs 之外工作,以便我可以使用 powershell isa 调试它

I know that there are things like PowerConsole that hook up with vs automatically, but in this case I want it to work outside of the vs so i can debug it with powershell isa

有什么想法吗?

推荐答案

您链接到的帖子使用 SharpDevelop 来允许在 Visual Studio 之外使用 NuGet PowerShell cmdlet.它不依赖于 Visual Studio,所以我认为打开 Visual Studio 的实例不会对您有帮助.

The post you linked to uses SharpDevelop to allow the use of NuGet PowerShell cmdlets outside of Visual Studio. It has no dependency on Visual Studio so I do not believe opening an instance of Visual Studio will help you.

显示错误是因为当前没有打开的解决方案.要打开解决方案,您可以使用 set-project cmdlet:

The error is being displayed because there is no solution currently open. To open a solution you can use the set-project cmdlet:

    set-project MyProject d:\Projects\MyProject\MySolution.sln

然后您应该可以调用 get-project cmdlet.

Then you should be able to call the get-project cmdlet.

这篇关于从 powershell 获取正在运行的 Visual Studio 实例 (DTE) 的句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆