从扩展程序运行时如何获取解决方案名称?

发布于 2024-10-07 03:15:41 字数 104 浏览 0 评论 0原文

我正在使用托管扩展性框架 (MEF) 用 C# 编写扩展。
如何获取当前打开的解决方案名称或项目名称?

我一直在深入挖掘的类是 IWpfTextView 但我没有找到它。

I'm coding an extension in C# using the Managed Extensibility Framework (MEF).
How can I get the current open solution name or the project names?

The class i'm been digging deep in is the IWpfTextView but I didn't find it.

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

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

发布评论

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

评论(1

勿忘初心 2024-10-14 03:15:41

如果程序集中有 Package 类,则可以执行以下操作:

DTE2 = Package.GetGlobalService(typeof(SDTE)) as DTE2;
字符串 fullName = dte.Solution.FullName;

否则,您可以通过以下方式获取 DTE:
DTE dte = System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE") 作为 DTE;
字符串 fullName = dte.Solution.FullName;

我看到人们谈论一种更面向“MEF”的获取 DTE 的方法,但我还没有尝试过。

一旦您拥有了 DTE 对象,您就可以使用解决方案遍历项目。

参考:VSIX:获取 DTE 对象
参考: http://msdn.microsoft.com/en-us/库/envdte.solution.aspx

If you have a Package class in your assembly, you can do:

DTE2 = Package.GetGlobalService(typeof(SDTE)) as DTE2;
string fullName = dte.Solution.FullName;

Otherwise you can get the DTE via:
DTE dte = System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE") as DTE;
string fullName = dte.Solution.FullName;

and I see people talk about a more 'MEF' oriented way of the getting the DTE but I've not tried it..

Once you have the DTE object you can then traverse the projects with the solution.

ref: VSIX: Getting DTE object
ref: http://msdn.microsoft.com/en-us/library/envdte.solution.aspx

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