本文介绍了在“全部"中断之后,有没有办法保留在当前文档上?在Visual Studio中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在调试时全部破坏"时,Visual Studio在堆栈顶部打开源代码.我想将光标停留在当前正在处理的文档上,而无需打开任何其他文档或窗口(例如:未加载任何符号).

Visual Studio opens source code on top of the stack when I "break all" while debugging; I want to keep the cursor on the document I'm currently working on, without any other document or window (e.g.: no symbols loaded) being opened.

推荐答案

有一种方法可以保留当前文档,但这需要在 Debug 工具栏.实际上,此答案的积分也应该转到 openshac ,后者发布了类似的SO ,并通过使用宏在他的OP中提供了解决方法.

There is a way to stay on the current document, but that requires creating a Visual Studio add-in and a new UI command in the Debug toolbar. Credits for this answer should actually also go to openshac, who posted a similar SO question and also gave a workaround in his OP by using a macro.

实现非常简单(我花了几分钟使它起作用).首先,在外接程序项目中,如下所示修改Connect.cs文件中的Exec方法:

The implementation is fairly simple (it took me a few minutes to have it working). First, in the add-in project, modify the Exec method in the Connect.cs file like this:

public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
{
    handled = false;
    if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
    {
        if(commandName == "BreakInCurrentDocument.Connect.BreakInCurrentDocument")
        {

            // here's where the magic happens
            // ******************************
            var activeWindow = _applicationObject.ActiveWindow;
            _applicationObject.Debugger.Break();
            if (_applicationObject.ActiveWindow != activeWindow)
            {
                _applicationObject.ActiveWindow.Close(vsSaveChanges.vsSaveChangesNo);
            }
            // ******************************

            handled = true;
            return;
        }
    }
}

创建并注册加载项后,只需:

After creating and registering the add-in, just:

  1. 在Visual Studio菜单上单击工具
  2. 自定义
  3. 命令
  4. 选择工具栏"单选按钮
  5. 选择调试"
  6. 添加命令...
  7. 从加载项"类别中,选择您的自定义加载项.
  1. click TOOLS on the Visual Studio's menu
  2. Customize
  3. Commands
  4. Choose the "Toolbar" radio button
  5. Select "Debug"
  6. Add Command...
  7. From the "Addins" category, choose your custom add-in.

就是这样.

这篇关于在“全部"中断之后,有没有办法保留在当前文档上?在Visual Studio中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 02:50