New option in Visual Studio 2019 keeps console window open after debugging
For as long as I've been writing console applications, I've at
the end of Main
I've always had a piece of code to require
user input before exiting when in debug mode, in order to review
any output before the window closes. Not an onerous task, but
one I immediately do as soon as creating a new application.
New features?
Today I created a new .NET Core console application in Visual Studio 2019 preview and added by code without a second thought.
When I ran the application I was in for two surprises - the first was the icon had changed, to a fetching purple. The second was, after the program had ran and displayed my usual "(Press any key to exit.)" message, the console stayed open - with another message to press a key to exit.
A small change, but a welcome one! And, just in case it's not to everyone's liking, there's even an option to disable the behaviour if you don't like it.
Always a catch
Unfortunately, this new option doesn't seem to work for old school console applications using the full .NET Framework, so I'll continue adding my boilerplate blocks to any new .NET Framework console applications I create.
Update History
- 2019-03-02 - First published
- 2020-11-22 - Updated formatting
Leave a Comment
While we appreciate comments from our users, please follow our posting guidelines. Have you tried the Cyotek Forums for support from Cyotek and the community?
Comments
larry andrews
#
This is quite messed up for console apps. The checkbox does nothing for a run under the debugger. It closes the output window whatever the checkbox is set to. This is the old behavior for debug runs. HOWEVER, for non-debug running of debug compilations, the new default if that the box is unchecked and the window closes immediately. Setting the checkbox (automatically close the console when debugging stops) changes the non-debug run to leave the console window open at the end of execution. Totally confusing and mislabeled. WORSE: if you are running Visual Studio 2017 also, the options apply there also, so you suddenly lose the output window in non-debug runs.
Richard Moss
#
Hello,
Thanks for taking the time to comment. I have to say, I didn't observe this behaviour myself. I never tried running non-debug builds as it is incredibly rare I build in release mode and then run it via Visual Studio, but my observations were it worked perfectly in debug mode for .NET Core console applications - I already noted that sadly it doesn't work for full .NET Framework applications, even in the RTM version (which is a shame, I still currently do more work in the full framework than core).
I don't have an answer on your woes with the output window either, while I'm currently running VS2019 on a fresh Windows install, prior to the RTM I was running both 2015 and 2017 and never identified any problems - the shells are seperate products with seperate configurations etc. That doesn't mean that VS2019 has some subtle bug of course, just that it's nothing I've experienced myself.
Regards;
Richard Moss
Mix-Movie.com
#
I had the same problem, when I created projects with the option "empty project", Create project as "Win32-console application" instead of "empty project". In the dialog which pops up now, you press "continue" and after that you may check the option "empty project" and press confirm. After that CTRL + F5 will open a console which does not close automatically.
Alex
#
You could use this extension for redirection stdout into Visual Studio output window https://marketplace.visualstudio.com/items?itemName=NesviatypaskhaOleksii.VsConsoleOutput