visual-studio VisualStudio:没有调试输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/935180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:35:42  来源:igfitidea点击:

VisualStudio: no debug output

visual-studiodebugging

提问by pistacchio

I'm trying to debug a C# application. The method:

我正在尝试调试 C# 应用程序。方法:

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

should do the work, but in the Output window (set to "debug" and with all the options activated) I can't see a single line I'm trying to write. Any idea? Thanks

应该完成这项工作,但在“输出”窗口(设置为“调试”并激活所有选项)中,我看不到我正在尝试编写的一行。任何的想法?谢谢

EDIT: I'm using VS2008

编辑:我正在使用 VS2008

回答by Richard Anthony Hein

There's an option under Tools-Options-Debugging-General, Redirect all Output Window text to the Immediate Window. Make sure that's disabled. However, by default it isn't, so I doubt that's your issue. You can also just check your Immediate Window to see if it's outputting there.

在工具-选项-调试-常规下有一个选项,将所有输出窗口文本重定向到立即窗口。确保它被禁用。但是,默认情况下不是,所以我怀疑这是您的问题。您也可以检查您的立即窗口以查看它是否在那里输出。

You might also want to try resetting all your environment settings. (Tools - Import and Export Settings - Reset all settings.)

您可能还想尝试重置所有环境设置。(工具 - 导入和导出设置 - 重置所有设置。)

回答by PaulS

Also worth checking - right-click in the output window, and ensure "Program output" is checked.

同样值得检查 - 在输出窗口中右键单击,并确保选中“程序输出”。

回答by JaredPar

Have you checked to make sure you're compiling in Debug mode? If you compile in Retail / Release mode you will see this behavior.

您是否检查过以确保在调试模式下进行编译?如果您在零售/发布模式下编译,您将看到此行为。

You should be able to see this information on Visual Studio's toolbar. There will be a combo box which will say Release or Debug. If it says Release, switch it to Debug.

您应该能够在 Visual Studio 的工具栏上看到此信息。将有一个组合框,上面会显示“发布”或“调试”。如果显示 Release,请将其切换为 Debug。

In certain profile settings, this combo box will not be visible by default. You'll have to access it through the project properties page. It will be on the build / compile tab.

在某些配置文件设置中,默认情况下此组合框将不可见。您必须通过项目属性页面访问它。它将在构建/编译选项卡上。

回答by Alexander Kahoun

Apart from the suggestions above, take a look at the project properties by right-clicking on the project name and selecting Properties. Once you have that up click on the Build taband then the Advanced buttonin the lower right. Once you have the Advancedwindow up, take a look at the Output sectionand the Debug Info:setting. When you are in debug mode this should be set to full.

除了上面的建议之外,通过右键单击项目名称并选择Properties来查看项目属性。完成后,单击“构建”选项卡,然后单击右下角的“高级”按钮。打开高级窗口后,查看输出部分调试信息:设置。当您处于调试模式时,这应该设置为full

回答by cfl

I had the same issue, got debug to show by selecting:

我遇到了同样的问题,通过选择来显示调试:

Debug -> Windows -> Output

调试 -> Windows -> 输出

However, my output is still now showing, so I guess vs will hide Debug until there is actual data being written out.

但是,我的输出现在仍在显示,所以我猜 vs 会隐藏调试,直到写出实际数据。

回答by Navaar

Also, make sure that your Output window is set to show "Debug" output instead of something else like "Build" output.

此外,请确保您的输出窗口设置为显示“调试”输出而不是“构建”输出之类的其他内容。

You should see it loading all the required assemblies in the "Debug" output.

您应该会看到它在“调试”输出中加载了所有必需的程序集。

回答by William Brendel

You need to explicitly add the system's Consoleas a TraceListenerin order for the output to appear in the console. According to Microsoft's documentation, this code should do the trick. This is C# code, but the link I provided contains examples for the other .NET languages.

您需要显式地将系统添加Console为 a TraceListener,以便输出显示在控制台中。根据微软的文档,这段代码应该可以解决问题。这是 C# 代码,但我提供的链接包含其他 .NET 语言的示例。

using System;
using System.Data;
using System.Diagnostics;

class Test
{
    static void Main()
    {
       Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
       Debug.AutoFlush = true;
       Debug.Indent();
       Debug.WriteLine("Entering Main");
       Console.WriteLine("Hello World.");
       Debug.WriteLine("Exiting Main"); 
       Debug.Unindent();
    }
}

回答by user2531685

"Enable the Visual Studio hosting process" under project properties -> Debug solved the issue for me.

项目属性下的“启用 Visual Studio 托管进程”-> 调试为我解决了这个问题。

回答by Serge Voloshenko

IF you use shortcuts, make sure you press F5to Start Debugging mode (not Ctr+F5).

如果您使用快捷方式,请确保按F5启动调试模式(而不是 Ctr+F5)。

F5Starting Debugging

CTRL+F5Starting Without Debugging

F5开始调试

CTRL+F5不调试启动

回答by InsperationalSensational

I just ran into this issue with Visual Studio 2010 and 2017 and this is what I did to get it to work and I have no explanation as to why it now works.

我刚刚在 Visual Studio 2010 和 2017 中遇到了这个问题,这就是我为让它工作而做的事情,我没有解释为什么它现在可以工作。

What I did to get it work. I created a new Windows Form project and added a button which when pressed executed Console.WriteLine("Test"). I saw "Test" in the Output Window. I then loaded my real project and added a button to execute Console.WriteLine("Test") and now it produced output. Further Console.WriteLine statements worked from then on.

我做了什么让它工作。我创建了一个新的 Windows 窗体项目并添加了一个按钮,按下时执行 Console.WriteLine("Test")。我在输出窗口中看到了“测试”。然后我加载了我的真实项目并添加了一个按钮来执行 Console.WriteLine("Test") 现在它产生了输出。从那时起,进一步的 Console.WriteLine 语句起作用了。