2013-06-13 25 views
6

Đối với VS 2012, tôi không thể để xóa sổ đầu ra debugger sử dụng sau MSDN code,Làm thế nào để xóa sổ đầu ra debugger Visual Studio 2012

Về cơ bản tôi không thể vượt qua đối tượng DTE2, để 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(); 
} 

Sử dụng liên kết SO khác không thể hoạt động cho VS2012.

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

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

Trả lời

4

Sau đây là cách tôi thực hiện nó. Lưu ý tham chiếu đến câu hỏi trả lời khác đã giúp tôi.

' #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 

'

+0

Thêm tham chiếu EnvDTE: cho VS10: C: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ Common7 \ IDE \ PublicAssemblies \ EnvDTE.dll – mvermand

+0

Trên hệ thống 64-bit của tôi (Windows 10 với Visual Studio 2015) 'EnvDTE.dll' được đặt dưới đường dẫn' C: \ Program Files (x86) \ Common Files \ Microsoft Shared \ MSEnv \ PublicAssemblies'. –

Các vấn đề liên quan