在Visual Studio中"全部中断"后,有没有办法保留当前文档?

cca*_*oni 17 c# visual-studio

当我在调试时"全部打破"时,Visual Studio会在堆栈顶部打开源代码; 我想将光标放在我正在处理的文档上,而不打开任何其他文档或窗口(例如:没有加载符号).

Ale*_*ici 10

有一种方法可以保留当前文档,但这需要在" 调试"工具栏中创建Visual Studio加载项和新的UI命令.这个答案的积分实际上也应该是 openshac,他发布了类似的SO 问题,并通过使用宏在他的OP中给出了解决方法.

实现相当简单(我花了几分钟才能使它工作).首先,在加载项项目中,修改文件中的Exec方法,Connect.cs如下所示:

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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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

  1. 单击Visual Studio菜单上的工具
  2. 定制
  3. 命令
  4. 选择"工具栏"单选按钮
  5. 选择"调试"
  6. 添加命令...
  7. 从"Addins"类别中,选择您的自定义加载项.

而已.


Jar*_*das 10

最新版本的VSCommands扩展(免费版)可从http://visualstudiogallery.msdn.microsoft.com/a83505c6-77b3-44a6-b53b-73d77cba84c8获得,这正是您想要的.它在Debug Toolbar和Debug Menu中添加了一个Break In Current Document按钮:

http://vscommands.squaredinfinity.com/Media/VSCommands/BlogPost//blog/breakincurrentdocument.png