hb.*_*hb. 9 .net c# visual-studio-2010 visual-studio vsix
我的Visual Studio包需要使用EnvDTE.DTE变量,但它总是返回null.在阅读了许多黑客之后,所有人都说要使用OnShellPropertyChange()方法(IVsShellPropertyEvents),但有时候它永远不会触发 - 好像我的扩展从未完成加载.
我正在使用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;
}
Run Code Online (Sandbox Code Playgroud)
编辑:在实验实例下,它完美地工作,初始化大约需要5秒钟.但是,一旦部署为VSIX - 它根本不会触发.
小智 27
请尝试以下命令:
dte = Package.GetGlobalService(typeof(DTE)) as DTE2;
Run Code Online (Sandbox Code Playgroud)
如果您有MEF组件,最简单的到达DTE
对象的方法如下
首先添加对Microsoft.VisualStudio.Shell.Immutable.10的引用.然后添加MEF导入SVsServiceProvider
.该对象具有可以查询的GetService方法DTE
[ImportingConstructor]
public MyComponent(SVsServiceProvider serviceProvider) {
_DTE dte = (_DTE)serviceProvider.GetService(typeof(_DTE));
}
Run Code Online (Sandbox Code Playgroud)
我在这看到几个问题:
归档时间: |
|
查看次数: |
8585 次 |
最近记录: |