【问题标题】:Is there a keyboard shortcut to enable/disable "Common Language Runtime Exceptions" in Visual Studio exception settings?在 Visual Studio 异常设置中是否有启用/禁用“公共语言运行时异常”的键盘快捷键?
【发布时间】:2020-09-27 13:14:56
【问题描述】:

我发现自己非常有规律地启用和禁用异常设置中的“公共语言运行时异常”复选框。我厌倦了每次都必须打开窗户。有快捷键吗?

编辑:由于截至 2020 年 6 月的答案似乎是“否”,我在此处请求了一个功能:https://developercommunity.visualstudio.com/idea/1073035/keyboard-shortcut-to-enabledisable-the-common-runt.html

【问题讨论】:

  • 快捷方式会很棒,但可能有点不太可能,因为它是“列表”中的复选框

标签: visual-studio visual-studio-2019 visual-studio-debugging


【解决方案1】:

是否有启用/禁用“通用语言”的键盘快捷键 Visual Studio 异常设置中的“运行时异常”?

我认为没有这么快的捷径可以做到这一点。

其实,异常窗口的快捷方式是Ctrl+Alt+E,你可以通过它调用这个窗口。

但是,VS只有打开窗口的快捷键,并没有开启或关闭异常的快捷键,并且异常窗口中的异常有很多不同的类型。所以这可能有点困难。

所以你应该使用快捷键Ctrl+Alt+E打开异常,然后手动设置异常。

此外,如果您仍然希望该功能有一个键盘快捷键来启用/禁用通用语言运行时异常,您可以在我们的User Voice Forum 上建议此功能。

之后,您可以在此处与我们分享链接,任何对此功能感兴趣的人都会对其进行投票,以便获得微软的更多关注。

【讨论】:

【解决方案2】:

由VSDebugCoreUI.dll中的DebuggerServiceHelper类管理:

ExceptionSettingsBatchOperation{_operationDepth=3} DebuggerServiceHelper.BeginExceptionBatchOperation()
DebuggerServiceHelper.UpdateException(EXCEPTION_INFO150{bstrProgramName=null, bstrExceptionName="Common Language Runtime Exceptions", dwCode=0, dwState=16418})
ExceptionSettingsBatchOperation.EndBatchOperation()

但这些都是内部类,不容易从外部代码访问。

另一种方法是在屏幕上找到这个 WPF CheckBox(通过带有给定 Text 属性的 TextBlock)并以编程方式单击它。

【讨论】:

    【解决方案3】:

    我真希望Exception Breaker 能用于更高版本的 Visual Studio。

    结合这个answer 到一个类似的问题,我能够得到一些工作。这并不理想,但您可以尝试一下。

    注意:我使用的是 Visual Studio 2019

    需要工具

    • Visual Commander 扩展的免费版本,允许在更高版本中使用 Visual Studio 宏。

    注意:我尝试(一点)使用Macros for Visual Studio 扩展,但没有成功

    步骤

    1. 使用 Visual Commander,使用以下代码添加新命令,保存并编译。
    2. 使用以下之一运行:
    • 直接从 Visual Commander UI 运行
    • 修改工具栏并向其添加 Extensions/Command01 命令
    • 通过选项添加键盘快捷键并选择 VCmd.Command01

    代码

    注意事项:

    • 我尝试切换 <All Common Language Runtime Exceptions not in this list> 项目,但没有成功。
    • 我尝试循环遍历组中的所有异常,但速度非常慢(即 15 秒 :-( ),因此我为我的项目选择了最重要的异常。
    • 我没有成功找到切换父级Common Language Runtime Exceptions 的方法,但如果您找到了,请发表评论。

    using EnvDTE;
    using EnvDTE80; // DTE2 type
    using EnvDTE90; // Debugger3
    
    public class M : VisualCommanderExt.ICommand
    {
        public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
        {
            var lDebugger = DTE.Debugger as Debugger3;
    
            var lExceptionSettings = lDebugger.ExceptionGroups.Item("Common Language Runtime Exceptions");
    
            // Use this Exception as the master toggle
            bool lExceptionsEnabledToSet = !lExceptionSettings.Item("System.ArgumentException").BreakWhenThrown;
    
            // 2 examples
            lExceptionSettings.SetBreakWhenThrown(lExceptionsEnabledToSet, lExceptionSettings.Item("System.ArgumentException"));
            lExceptionSettings.SetBreakWhenThrown(lExceptionsEnabledToSet, lExceptionSettings.Item("System.OutOfMemoryException"));
    
            // This does not work to set the whole group on/off:
            //lExceptionSettings.SetBreakWhenThrown(true, lExceptionSettings.Item("<All Common Language Runtime Exceptions not in this list>"));
    
            // This is really slow
            //foreach (var lExceptionSetting in lExceptionSettings)
            //{
            //    lExceptionSettings.SetBreakWhenThrown(lExceptionsEnabledToSet, lExceptionSetting as ExceptionSetting);
            //}
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-31
      • 2017-05-16
      • 1970-01-01
      • 1970-01-01
      • 2016-09-25
      • 2021-06-06
      • 1970-01-01
      相关资源
      最近更新 更多