13

When I start a Console App (.NET Core) with Ctrl+F5 (Start Without Debugging) in Visual Studio Community 2019 (Version 16.3.1), the following message is appended in the Console window at the end:

C:\HelloWorld\bin\Debug\netcoreapp3.0\HelloWorld.exe (process 1672) exited with code 0.

using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

Console output

Is there any way to prevent Visual Studio 2019 from printing this message? I tried the solution from preventing a similar message from appearing in the Output Window, by changing the option: Tools > Options > Debugging > Output Window > Process Exit Messages = Off, but it has no effect in the Console Window.

Visual Studio Options

Note: this message is not shown in Visual Studio 2017. It is only shown in Visual Studio 2019, and only on .NET Core apps.

Note 2022: the accepted answer is not working on Visual Studio 2022 version 17.4.0 (the latest version).

Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
  • Its the community spirit. Anyway this might be a bug – TheGeneral Oct 01 '19 at 06:38
  • 1
    If you are sure that this happens even on a freshly installed instance of Visual Studio 2019, I would create an issue over on the forum. You can do this by hitting `Help > Send Feedback > Report a Problem` – Twenty Oct 01 '19 at 06:47
  • 1
    @Twenty I updated the Visual Studio with the latest version a few days ago. I don't remember if it was the same before the update, because I was working with VS 2017. I am not sure if it's a problem or a feature. It may be configurable somewhere in the Options. – Theodor Zoulias Oct 01 '19 at 06:54
  • Why is this a problem? Ctrl-F5 is for testing (and knowing the exit code is helpful feedback when it is significant). Any real use of a console app wouldn't be from within VS. – Richard Oct 01 '19 at 07:43
  • @Richard during development I press frequently Ctrl-F5 to test my app, and the AppPath/ProcessId/ExitCode message is zero value information that steals my attention from what I really want to see. If my application makes use of the exit code (rarely does), I could print it myself. – Theodor Zoulias Oct 01 '19 at 08:43
  • 5
    For VS2019 this is feature, not a bug. It addresses a 28 year old complaint from programmers that write small console mode apps, they always forgot to add "Press any key to continue" code or setting a breakpoint at the end of main. So they couldn't read the output of their program, many many questions about it at SO and the forums. In VS2019 the console window no longer closes. And dutifully reports that the program ended. This is a pure debugger feature, you won't see this when you run the program normally. – Hans Passant Oct 01 '19 at 09:41
  • @HansPassant the "Press any key to continue" message was always there for Ctrl+F5 (personal experience from VS2008, VS2017, VS2019). I don't mind that, it is helpful. What annoys me is the long exit-code message that is printed before the press-to-continue message. – Theodor Zoulias Oct 01 '19 at 09:51
  • Could I ask why this is a problem, out of interest? – Kieren Johnstone Oct 03 '19 at 20:44
  • @KierenJohnstone it's a little annoyance I would happily live without. :-) – Theodor Zoulias Oct 03 '19 at 20:46
  • 1
    I don't know if this will be possible without a VS setting. `Console` exposes it output stream through [Console.Out](https://learn.microsoft.com/en-us/dotnet/api/system.console.out) and a setter through `Console.SetOut`, but those extra lines are written to stdout directly. So we don't have a way to intercept them. – Funk Nov 18 '22 at 07:26

1 Answers1

16

You can disable it by checking the Tools > Options > Debugging > General > Automatically close the console when debugging stops option:

Visual Studio 2019 Options

As stated by the console itself (Visual Studio 2019 v16.3.2):

Console App

That will make the console just print Press any key to continue... by starting without debugging (CTRL + F5) and not the exit code (still leaves the console open):

No exit code

  • Ahhh! Nice find Ivan! Thank you so much! – Theodor Zoulias Oct 03 '19 at 23:00
  • 2
    I just installed the Visual Studio 2022 version 17.4.0, the version that supports the new .NET 7, and the above configuration no longer prevents the *"exited with code 0."* message from appearing in the Console (without debugging). :-( [Screenshot](https://prnt.sc/nEZFuHbBM4j1). – Theodor Zoulias Nov 13 '22 at 09:53