双击以在“输出"窗口中找到源 [英] Double click to go to source in Output Window

查看:85
本文介绍了双击以在“输出"窗口中找到源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio中生成项目时,输出"窗口将输出生成过程的状态,其中包括错误和警告.双击这些行将在编辑器中打开包含该错误/警告的文件.

When you build a project in Visual Studio, the Output Window outputs the status of the build process, which included errors and warnings. Double clicking those lines will open up the file containing that error/warning in the editor.

现在,是否可以从Debug.WriteLine或类似的输出中获得该功能?这样,例如在调试"窗口输出时

Now, is it possible to get that functionality with output from Debug.WriteLine, or anything like that? So that when the Debug window outputs for example

Buffering: 13:03:20 to 13:03:21

我将可以双击它,并转到BufferClass.cs,第45行,因为那是Debug.WriteLine调用的位置.

I would be able to double click it and be taken to BufferClass.cs, line 45, since that was the location of the Debug.WriteLine call.

是否可以通过.net库或Visual Studio扩展?

Is that possible, either through .net libraries, or through a Visual Studio Extension?

推荐答案

我将继续自己回答.

要能够直接跳至源文件,请按以下格式设置消息:

To be able to directly jump to the source file, format your message like this:

string.Format("{0}({1})", filePath, lineNumber);

这样,Visual Studio将自动添加双击功能并将您直接带到源代码.

That way, Visual Studio will automatically add the double click functionality and take you directly to the source.

此外,如果您使用Visual Studio 2012中的新功能,如此处所述:

Additionally, if you use the new functionality in Visual Studio 2012, as described here: Caller Details, you can implement your Log Method like this:

private void LogData(string message, 
                     [CallerMemberName] string callerName = "",
                     [CallerLineNumber] int lineNumber = -1,
                     [CallerFilePath] string filePath = "")
    {
        Debug.WriteLine(message);
        Debug.WriteLine(string.Format("    {0}({1})", filePath, lineNumber));
    }

此外,添加":错误"或:警告"最终使Visual Studio将其颜色变为红色或黄色. 如果有任何进一步描述这一点的文章,我真的很想知道.

In addition, adding " : error" or ": warning" to the end makes Visual Studio color it red or yellow. If there are any articles describing this further, I'd really like to know.

这篇关于双击以在“输出"窗口中找到源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆