我只是打开一个控制台应用程序,然后输入

Console.WriteLine("Test");

但是输出窗口没有显示这一点。我用Ctrl + W, O切换到输出窗口。

但是当我运行程序时什么都没有显示。是我疯了还是这在Visual Studio 2010 Express中不支持?


控制台。WriteLine将输出写入应用程序打开的控制台窗口(想象一下当您打开命令提示符时出现的带有白色文本的黑色窗口)。试试System.Diagnostics.Debug.WriteLine吧。


也许控制台正在清理。试一试:

Console.WriteLine("Test");
Console.ReadLine();

在你按回车键之前,它会一直在那里。


输出窗口不是控制台。尝试System.Diagnostics.Debug中的方法


或者你可以通过CTRL+F5进行调试,这将打开ConsoleWindow等待最后一行执行,直到你按下键。


Console.Writeline()显示在调试输出中(debug => Windows => output)。


在“解决方案资源管理器”窗口中转到您自己项目中的属性,选择应用程序类型并查找“输出类型”。

将其值更改为控制台应用程序。

这将使控制台屏幕除了你的形式。如果您关闭控制台屏幕,您的表单也将被关闭。


在解决方案资源管理器中右键单击项目,然后单击“清洁”。

现在运行-按F5。

确保代码如下所示:

Console.WriteLine("TEST");
Console.ReadLine();

这很可能是因为您在名称空间中使用了Console。比如这样:

namespace XYZApplication.Console
{
    class Program
    {
        static void Main(string[] args)
       {
            //Some code;             
       }
    }
}

尝试从命名空间中删除它或使用完整的命名空间。

   System.Console.Writeline("abc");

这是一个问题这是一个问题是因为您可能有另一个冲突的名称空间。例子:

using System;
using AnotherNamespaceThatContainsAConsoleClass;

我在运行单元测试时遇到了类似的问题。Console.WriteLine()没有向Visual Studio输出窗口写入任何内容。

使用System.Diagnostics.Debug.WriteLine()解决了这个问题。


尝试按Ctrl + F5。它将保持你的屏幕,直到你按下任何键。


没有提供令人满意的答复。

System.Diagnostics.Debug.WriteLine()将向Output:debug窗口写入消息,但如此多的垃圾被太阳下的每个进程不断地倾倒到该窗口中,这就像大海捞针一样。

Console.WriteLine()不会写入Visual Studio中的任何窗口。我猜只有当你的应用程序首先创建了一个控制台,也就是说,如果它是一个控制台应用程序,它才会写入应用程序控制台。


在Windows窗体应用程序中,

System.Diagnostics.Debug.WriteLine("my string")

and

System.Console.WriteLine("my string")

写入输出窗口。

在ASP中。NET核心应用,只有System.Diagnostics.Debug。WriteLine("my string")写到输出窗口。


如果你使用Ctrl-F5(启动不调试),它将留下控制台窗口打开的消息“按任意键继续”。这是防止控制台窗口关闭的最简单方法,这样您就可以看到控制台输出。


如果你正在开发一个命令行应用程序,你也可以在你的代码末尾使用console . readline()来等待'Enter'键,然后关闭控制台窗口,这样你就可以读取输出。


using System.Diagnostics;


Trace.WriteLine("This line will show on Output window"); 
Trace.Flush();

这适用于Microsoft Team Explorer for Visual Studio 2013

参考microsoft.com


打开调试菜单,选择“选项”,取消选中“将所有输出窗口文本重定向到即时窗口”。


我找到了一个变通办法:

按Ctrl + Alt + I或导航到调试选项卡→Windows→立即。

在你的代码中写:

Trace.WriteLine("This is one of the workarounds");

Visual Studio 2017的输出窗口有一个名为Show Output from的菜单,在我的例子中是ASP。NET Core Web Server选项是为了看到打印出来的,我遇到了这个问题,因为我把它设置为构建,所以我在运行时看不到打印出来的行。


有两个可能的问题:

首先,在编写使用“System类”的代码之前,你没有使用过using System,比如Console.WriteLine() 其次,您还没有编写控制台显示“Test”后发生的事情。

可能的解决方案是:

using System;

namespace Test
{
    public static Main()
    {
        //Print to the console
        Console.WriteLine("Test");

        //Allow user to read output
        Console.ReadKey();
    }
}

编写控制台代码也是有战略意义的。写(“按任意键退出…”);在Console.ReadKey()之前的行;为了让用户意识到程序正在结束,他/她必须按任意键退出。


这里没有一个答案对我有用!!这里的大多数人都被困在Windows桌面应用程序控制台。如果你是一个使用ASP的web开发人员。NET在Visual Studio中看不到任何控制台或调试文本,下面是如何修复这个问题:

Paste the following two tests into your code so it runs both lines. These are tests for the output window: System.Console.WriteLine($"hello console!"); System.Diagnostics.Debug.WriteLine($"hello debugger!"); In Visual Studio choose VIEW > OUTPUT. You will see the results above in this output window after changing two settings below. When NOT DEBUGGING, in the OUTPUT window at the top under "Show Output From" choose: "YourProjectName - ASP.NET CORE Web Server". Run your code. You should see the "Console" text above. When DEBUGGING, in the OUTPUT window at the top under "Show Output From" choose: "Debugger". Run your code in debug mode. You should see the "Debug" text above.


将执行模式改为“Self - Hosted”。在这种情况下,将出现执行控制台,并显示所有消息。