如何在EnvDTE.Events.DebuggerEvents的处理程序中确定已调试的程序/进程



我正在创建一个Visual Studio扩展,它在特定应用程序的调试停止时执行一些任务。这是我处理调试器事件的代码:

...
DTE2 ide = Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;
if (ide != null)
{
debuggerEvents = ide.Events.DebuggerEvents;
debuggerEvents.OnEnterDesignMode += DebuggerEvents_OnEnterDesignMode;
}
}
private static void DebuggerEvents_OnEnterDesignMode(dbgEventReason Reason)
{
ThreadHelper.ThrowIfNotOnUIThread();
DTE2 ide = Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;
if (ide != null && ide.Debugger.CurrentProcess != null)
{
DebuggedProcName = ide.Debugger.CurrentProcess.Name;
}
if (Reason == dbgEventReason.dbgEventReasonStopDebugging &&
DebuggedProcName == "MyApp")
{
...
}
}

问题是ide。调试器.CurrentProcess和.CurrentProgram在OnEnterDesignMode((中为null。它们在OnEnterBreakMode((中不为null,但可能不会调用该值。如何确定Visual Studio扩展中当前调试的程序/进程?

如果某个项目的调试停止,我想执行一项特定的任务。由于使用事件处理程序似乎是不可能的,所以我用了一个菜单命令来帮助自己,该命令在我按下Ctrl+F5时执行。执行任务后,此命令还会终止已调试的进程,从而有效地停止调试。我想这相当粗鲁,但我可以接受这个解决方案。

相关内容

最新更新