问题描述
当我在调试时全部破坏"时,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:
- 在Visual Studio菜单上单击工具
- 自定义
- 命令
- 选择工具栏"单选按钮
- 选择调试"
- 添加命令...
- 从加载项"类别中,选择您的自定义加载项.
- click TOOLS on the Visual Studio's menu
- Customize
- Commands
- Choose the "Toolbar" radio button
- Select "Debug"
- Add Command...
- From the "Addins" category, choose your custom add-in.
就是这样.
这篇关于在“全部"中断之后,有没有办法保留在当前文档上?在Visual Studio中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!