开发者

Why doesn't Console.Writeline, Console.Write work in Visual Studio Express?

I just open a console application and I type

Console.WriteLine("Test");

But the output window doesn't show this. I go to the output window with Ctrl + W, O.

But nothi开发者_如何学编程ng shows up when I run my program. Am I nuts or is this not supported in Visual Studio 2010 Express?


Console.WriteLine writes your output to the console window opened by your application (think black window with white text that appears when you open the Command Prompt.) Try System.Diagnostics.Debug.WriteLine instead.


No satisfactory answers were provided.

System.Diagnostics.Debug.WriteLine() will write messages to the Output:debug window, but so much crap is constantly dumped into that window by every process under the sun, it is like finding a needle in a haystack to find your messages.

Console.WriteLine() does not write to any window in Visual Studio. I guess it will only write to the application console if your application creates a console in the first place, i.e. if it is a console application.


Go to properties in you own project in the Solution Explorer window and choose application type and look for Output Type.

Change its value to Console Application.

This will make console screen besides your form. If you close the console screen, your form will be closed too.


Perhaps the console is clearing. Try:

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

And it will hopefully stay there until you press enter.


Or you can debug by CTRL+F5 this will open ConsoleWindow waits after last line executed untill you press key.


It's more than likely because you've used Console in the namespace. For example like this:

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

Try removing it from the namespace or use the full namespace instead i.e.

   System.Console.Writeline("abc");

The reason is a problem this is an issue is because you might have another clashing namespace. Example:

using System;
using AnotherNamespaceThatContainsAConsoleClass;


The output window isn't the console. Try the methods in System.Diagnostics.Debug


Try Ctrl + F5. It will hold your screen until you press any key.


I run into a similar problem while running a unit test. Console.WriteLine() did not write anything into the Visual Studio Output Window.

Using System.Diagnostics.Debug.WriteLine() solved the problem.


In a Windows Forms application, both methods,

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

and

System.Console.WriteLine("my string")

write to the output window.

In an ASP.NET Core application, only System.Diagnostics.Debug.WriteLine("my string") writes to the output window.


None of the answers here worked for me!! Most of these people here are stuck in Windows Desktop Application Consoleland. If you are a web developer using ASP.NET in Visual Studio and do not see any console or debug text, here is how to fix that:

  1. 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!");

  2. In Visual Studio choose VIEW > OUTPUT. You will see the results above in this output window after changing two settings below.

  3. 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.

  4. 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.


Right click on the project in Solution Explorer and click "Clean".

Now run - press F5.

Make sure the code is as below:

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


If you use Ctrl-F5 (start without debugging) it will leave the console window open with a message "Press any key to continue". That's the easiest way to keep the console window from closing so you can see the console output.


Go to the Debug menu and select Options and uncheck "Redirect all Output Window text to Immediate Window"


Console.Writeline() shows up in the debug output (Debug => Windows => Output).


If you are developing a command line application, you can also use Console.ReadLine() at the end of your code to wait for the 'Enter' keypress before closing the console window so that you can read your output.


using System.Diagnostics;


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

This works on Microsoft Team Explorer for Visual Studio 2013

Refer to microsoft.com


The Output window of Visual Studio 2017 have a menu called Show output from, in my case ASP.NET Core Web Server was the option to select in order to see the printed out, I came across this issue since I had it set to Build so I wasn't seeing the printed out lines at runtime.


There are 2 possible problems are:

  • Firstly, you have not used the using System which should be before writing code that uses "System class", as Console.WriteLine()
  • Secondly, you have not coded what happens after the Console displays "Test"

The possible solution will be:

using System;

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

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

It is also strategic to code Console.Write("Press any key to exit..."); on the line that precedes the Console.ReadKey(); to make the user aware that the program is ending, he/she must press any key to exit.


Change the execution mode to "Self Hosted". In this case, the execution console will appear and all the messages will be displayed.


A workaround I found:

Press Ctrl + Alt + I or navigate to the Debug tab → WindowsImmediate.

In your code write:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜