我的Visual Studio插件需要使用EnvDTE.DTE变量,但它总是返回null。阅读了许多窍门后,它们都建议使用OnShellPropertyChange()方法(IVsShellPropertyEvents),但有时它就是不会触发-就好像我的扩展程序永远无法完成加载一样。
我正在使用VS2010,并检查VSSPROPID_Zombie和ShellInitialized两个参数,但它们都没有用。:(
有什么想法吗?这是我正在使用的代码:
我正在使用VS2010,并检查VSSPROPID_Zombie和ShellInitialized两个参数,但它们都没有用。:(
有什么想法吗?这是我正在使用的代码:
public int OnShellPropertyChange(int propid, object var) {
if (propid == -9053 || (int) __VSSPROPID.VSSPROPID_Zombie == propid) { // -9053 = ShellInit
try {
if ((bool) var == false) {
Dte = GetService(typeof (SDTE)) as DTE;
Flow.Dte = Dte;
var shellService = GetService(typeof (SVsShell)) as IVsShell;
if (shellService != null)
ErrorHandler.ThrowOnFailure(shellService.UnadviseShellPropertyChanges(_cookie));
_cookie = 0;
}
} catch {
}
}
return VSConstants.S_OK;
}
编辑:在实验性实例下,它可以完美地工作,并且需要约5秒钟来初始化。但是,一旦部署为VSIX,它就不能正常启动。