Visual Studio 2022 on Windows 11 reuses the same console window on successive runs, overwriting the previous output

SneakyOwl 30 Reputation points
2023-10-21T21:14:20.8133333+00:00

I've just installed VS 2022 on a new Windows 11 computer, and as the title says, it has a new behavior that I've never seen in 25+ years. When running without debug (F8), the console window is reused over successive runs, with the previous output being erased and overwritten instead of creating a new window and outputting there. This is quite annoying because I need to see each run separately to compare how code changes affect the result.

How do I change this back to the old behavior, other than by a hack like adding system("pause");at the end of the file to prevent main() from returning?

There's an unanswered stack exchange question about this same problem here: https://stackoverflow.com/questions/54657838/how-can-new-console-windows-be-created-for-each-run-when-running-a-console-progr and here: https://stackoverflow.com/questions/77335564/visual-studio-2022-on-windows-11-reuses-the-same-console-window-on-successive-ru

I have VS 2022 community running on Windows 10 and it does not do this; i.e. each run spawns a separate console window.

Developer technologies | Visual Studio | Other
{count} vote

Accepted answer
  1. Tianyu Sun-MSFT 34,441 Reputation points Microsoft External Staff
    2023-10-24T07:50:52.79+00:00

    Hello @SneakyOwl ,

    Welcome to Microsoft Q&A forum.

    Perhaps this issue appeared after version 17.5. For different project types, the situation may be different(for example, VS 2022 version 17.5 added support for ASP.NET to redirect output to the Integrated Terminal Tool Window instead of an external console Window).

    Based on the tests, on machine with Windows 10, VS 2019 still uses the CMD and every time you start project without debugging, previous opened console window will not be closed, instead a new console window will open. But on the machine with Windows 10, VS 2022 17.7(I believe other versions higher than 17.5 will get the same result), the issue you described above appears(VS 2022 uses Microsoft Visual Studio Debug Console by default). And on machine with Windows 11, VS 2019 still opens multiple CMD window. So this issue is not related to or not only related to Windows versions/Terminal but is more related to VS/VS versions.

    Currently no options can be selected to change to the situation like previous in VS 2019.

    I notice that you have found one workaround => creating and using shortcut keys to run the project by executing external tools(cmd with commands/arguments). Other workarounds may not be better than this one, but I still strongly recommend submitting a suggestion ticket on our Developer Community.

    Thanks for helping us make Visual Studio better.

    Best Regards,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Ayla Naseer 100 Reputation points
    2023-10-21T23:02:32.97+00:00

    The behavior you are describing is a new feature in Visual Studio 2022 that is designed to improve performance. When you run a console application without debugging, Visual Studio will now reuse the same console window for successive runs. This can be helpful if you are running the same application multiple times and want to see the output from all of the runs in the same window.

    However, if you prefer the old behavior of creating a new console window for each run, you can change this setting. To do this, open the Visual Studio options dialog (Tools > Options) and navigate to the Debugging > General page. Uncheck the checkbox for "Reuse Console Window".

    Once you have changed this setting, Visual Studio will create a new console window for each run of your console application.

    If you are still having problems, you can try adding the following line of code to the end of your main() function:

    system("pause");

    This will cause the console window to pause until the user presses a key. This can be helpful if you want to make sure that you have seen all of the output from the application before the console window closes.

    P.S: You may find discussion more helpful here https://www.windowsphoneinfo.com/threads/visual-studio-community-2022-reuses-console-window.1087795/


  2. Ayla Naseer 100 Reputation points
    2023-10-22T08:12:30.2766667+00:00

    I must admit I was mistaken. The previous output is erased, not appended to. The information I provided about the "Reuse Console Window"

    The developers are aware of the problem and are working on a fix. In the meantime, there is no workaround other than adding the system("pause") line of code to the end of your main() function.

    This will cause the console window to pause until the user presses a key. This can be helpful if you want to make sure that you have seen all of the output from the application before the console window closes.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.