获取活动的 Visual Studio 对象

发布于 2024-09-28 04:16:07 字数 276 浏览 1 评论 0原文

使用此代码,我得到代表 Visual Studio 的对象:

var dte2 = Marshal.GetActiveObject("VisualStudio.DTE.10.0") as DTE2;

但是,当我打开多个 VS 实例时,这会返回 VS 的任何实例,而不是我当前正在执行代码的实例。

我不在加载项内,因此无权访问 applicationObject。

如何获取当前的 Visual Studio 实例?

多谢。

using this code I get the object representing Visual Studio:

var dte2 = Marshal.GetActiveObject("VisualStudio.DTE.10.0") as DTE2;

However, when I have multiple instances of VS opened, this returns any instance of VS, not the one I am currently executing the code from.

I am not within an add-in so I don't have access to the applicationObject.

How can I get the current Visual Studio instance??

Thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑着哭最痛 2024-10-05 04:16:07

尝试使用 Windows API 拉动活动窗口句柄(前台窗口)。

Try pulling the Active Window Handle (Foreground Window) with the Windows API's.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文