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