Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programatically clean output in Visual Studio 2013

I print output on the console in WPF and ASP.NET-MVC applications by:

System.Diagnostics.Debug.WriteLine("text");

how to programatically clear the output window?

like image 943
Duke Nuke Avatar asked Sep 02 '14 15:09

Duke Nuke


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 get the output code for Visual Studio?

To display the Output window whenever you build a project, in the Options dialog box, on the Projects and Solutions > General page, select Show Output window when build starts.

Where is the console output in Visual Studio?

Press F11 . Visual Studio calls the Console. WriteLine(String, Object, Object) method. The console window displays the formatted string.

How do I get console WriteLine output in Visual Studio?

In Visual Studio uppermost menu choose Debug > Windows > Output. It shows all Console. WriteLine("Debug MyVariable: " + MyVariable) when you get to them.


2 Answers

// Import EnvDTE and EnvDTE80 into your project
using EnvDTE;
using EnvDTE80;

protected void ClearOutput()
{
    DTE2 ide = (DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.12.0");
    ide.ToolWindows.OutputWindow.OutputWindowPanes.Item("Debug").Clear();
    System.Runtime.InteropServices.Marshal.ReleaseComObject(ide);
}
like image 54
entropic Avatar answered Nov 24 '22 07:11

entropic


This is what I use in VS2013, Win10, x64:

private static void ClearVS2013DebugWindow()
{
    // add reference to "C:\Program Files (x86)\Common Files\microsoft shared\MSEnv\PublicAssemblies\envdte.dll"
    EnvDTE.DTE ide = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.12.0");
    if (ide != null)
    {
        ide.ExecuteCommand("Edit.ClearOutputWindow", "");
            System.Runtime.InteropServices.Marshal.ReleaseComObject(ide);
    }
}

Credit to the answers above.

like image 27
Hadar Ben David Avatar answered Nov 24 '22 09:11

Hadar Ben David