我有在Visual Studio 2010中成功运行的加载项,但是在Visual Studio 2012中运行该加载项时,不会触发DebuggerEvents.OnEnterRunMode事件.
在MSDN中,Visual Studio 2010和Visual Studio 2012之间的DebuggerEvents事件没有任何变化.
我的代码是:
static DebuggerEvents dbgEvents;
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
dbgEvents = _applicationObject.Events.DebuggerEvents;
...
if (registered)
{
return;
}
dbgEvents.OnEnterRunMode += new _dispDebuggerEvents_OnEnterRunModeEventHandler(DebuggerEvents_OnEnterRunMode);
dbgEvents.OnEnterDesignMode += new _dispDebuggerEvents_OnEnterDesignModeEventHandler(dbgEvents_OnEnterDesignMode);
registered = true;
}
void DebuggerEvents_OnEnterRunMode(dbgEventReason Reason)
{
...
}
触发了OnConnection()和其他事件,例如SolutionEvents.Opened,但是当我单击“开始”以在Visual Studio中运行项目时,未调用事件OnEnterRunMode.
有任何想法吗?
解决方法:
我找到了解决方案:
DebuggerEvents.OnEnterRunMode()事件使用EnvDTE.dll.
当EnvDTE.dll嵌入互操作类型的属性为True时,不会触发DebuggerEvents.OnEnterRunMode事件.