visual-studio-2019 - 如何在 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.Debugger.CurrentProcess 和 .CurrentProgram 在 OnEnterDesignMode() 中为空。它们在 OnEnterBreakMode() 中不为空,但可能不会被调用。如何确定 Visual Studio 扩展中当前调试的程序/进程?
解决方案
如果某个项目的调试停止,我想执行一项特定任务。由于使用事件处理程序似乎不可能,我帮助自己使用了一个在按 Ctrl + F5 时执行的菜单命令。执行任务后,此命令还会终止已调试的进程,从而有效地停止调试。我想这很粗鲁,但我可以接受这个解决方案。
推荐阅读
- c++ - 返回值的简单模板类成员函数特化
- c++ - 如何为 GSL(GNU 科学库)适配 C++ 风格的随机数引擎?
- docker - Kubernetes ConfigMaps 卷挂载问题
- jquery - 如何在 Jquery 表上动态显示按钮
- angular - 导出 p-datatable 中的特定列
- google-cloud-platform - 是否有关于如何在 BigQuery 中转置(列 <--> 行)的建议,其中输入的行数超过 10,000 行?
- networking - 使另一个服务器网络跃点
- php - 通过 IDM(Internet 下载管理器)使用 PHP 下载文件
- .net - 具有多个表的 Dapper 一对多
- server - 在 DigitalOcean 服务器上上传文件