How to acquire DTE object instance in a VS package project?

依然范特西╮ 提交于 2019-11-28 06:32:35

问题


How can I get DTE instance in a VS package project? It's straigtforward in addin project since application is being passed as an argument to onConnection method, but it is unclear how to get it in a package.


回答1:


From your main Package class:

EnvDTE80.DTE2 dte = this.GetService(typeof(Microsoft.VisualStudio.Shell.Interop.SDTE)) as EnvDTE80.DTE2;



回答2:


You can get a null instance getting the SDTE service if the shell is not fully initialized. See how to handle that in this code sample:

HOWTO: Get the EnvDTE.DTE instance from a package



来源:https://stackoverflow.com/questions/19087186/how-to-acquire-dte-object-instance-in-a-vs-package-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!