visual-studiooutput-window

Double click to go to source in Output Window


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.

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

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.

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


Solution

  • I'll just go ahead and answer this by myself then.

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

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

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

    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));
        }
    

    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.