Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear debugger output window Visual Studio 2012

For VS 2012, I am not able to clear debugger output window using following MSDN code ,

Basically I am not able to pass DTE2 object, to ClearExample.

public void ClearExample(DTE2 dte)
{
    // Retrieve the Output window.
    OutputWindow outputWin = dte.ToolWindows.OutputWindow;

    // Find the "Test Pane" Output window pane; if it doesn't exist, 
    // create it.
    OutputWindowPane pane = null;
    try
    {
        pane = outputWin.OutputWindowPanes.Item("Test Pane");
    }
    catch
    {
        pane = outputWin.OutputWindowPanes.Add("Test Pane");
    }

    // Show the Output window and activate the new pane.
    outputWin.Parent.AutoHides = false;
    outputWin.Parent.Activate();
    pane.Activate();

    // Add a line of text to the new pane.
    pane.OutputString("Some text." + "\r\n");

    if (MessageBox.Show("Clear the Output window pane?", "", 
        MessageBoxButtons.YesNo) == DialogResult.Yes)
        pane.Clear();
}

Using other SO links couldn't make it work for VS2012.

Is it possible to programmatically clear the Ouput Window in Visual Studio?

Can the Visual Studio (debug) Output window be programatically cleared?

like image 799
Abhijeet Avatar asked Jun 13 '13 20:06

Abhijeet


People also ask

How do I fix the Output window in Visual Studio?

To display these options, open the Tools menu, click Options, expand the Debugging node, and click Output Window. General Output Settings This category contains controls that determine whether general debug messages appear in the Output window. You can specify whether each type of message appears.

How do I clear immediate window in Visual Studio?

To clear the immediate window, you can use >cls , which is a predefined command alias to >Edit. ClearAll .

What is Visual Studio output window?

The Output window displays status messages for various features in the integrated development environment (IDE).

How do I reset Visual Studio exceptions?

To set Visual Studio debugger options, select Tools > Options, and under Debugging select or deselect the boxes next to the General options. You can restore all default settings with Tools > Import and Export Settings > Reset all settings.


1 Answers

Here is how I implemented it. Note the reference to another question-answer that helped me.

'   #region ClearOutputWindow
    /// <summary>
    /// Clear the Output window-pane of Visual Studio.
    /// Note: Causes a 1-second delay.
    /// </summary>
    public static void ClearOutputWindow()
    {
        if (!Debugger.IsAttached)
        {
            return;
        }

        //Application.DoEvents();  // This is for Windows.Forms.
        // This delay to get it to work. Unsure why. See http://stackoverflow.com/questions/2391473/can-the-visual-studio-debug-output-window-be-programatically-cleared
        Thread.Sleep(1000);
        // In VS2008 use EnvDTE80.DTE2
        EnvDTE.DTE ide = (EnvDTE.DTE)Marshal.GetActiveObject("VisualStudio.DTE.10.0");
        if (ide != null)
        {
            ide.ExecuteCommand("Edit.ClearOutputWindow", "");
            Marshal.ReleaseComObject(ide);
        }
    }
    #endregion

'

like image 136
JamesWHurst Avatar answered Oct 20 '22 14:10

JamesWHurst