在WPF和ASP.NET-MVC应用程序中,我通过以下方式将输出打印到控制台:
System.Diagnostics.Debug.WriteLine("text");
如何通过编程方式清除输出窗口?
在WPF和ASP.NET-MVC应用程序中,我通过以下方式将输出打印到控制台:
System.Diagnostics.Debug.WriteLine("text");
// 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);
}
这是我在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);
}
}
在底层API中,调试输出是一个单向流 - 你不应该假设它只能在Visual Studio中查看。调试输出只能由应用程序编写,如果需要更详细的控制,则应显示在应用程序的用户界面中(无论是控制台窗口,可以清除; 还是WinForms应用程序,或WPF等)