How to set a custom PS profile for VS Start Without Debugging action?

Igor Pavlov 0 Reputation points
2023-12-27T15:03:36.6833333+00:00

When console app is launched with the Start Without Debugging action, the Visual Studio (VS) 2022 opens a default PowerShell (PS) console for it. I would like to use a custom PS profile for that. How it can be done?

The issue that I would like to solve is to prevent the console window from closing after a launched process termination. The feature was working in the previous VS versions but stopped working at some moment. It seems the VS doesn't control the console window closing anymore. PS has a setting to control behavior on profile termination, by default it closes the console windows. I would like to keep all of the console windows that were launched from the VS, but I don't want to change the default PS behavior.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,228 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Tianyu Sun-MSFT 31,416 Reputation points Microsoft Vendor
    2023-12-28T03:40:15.9566667+00:00

    Hello @Igor Pavlov,

    Welcome to Microsoft Q&A forum.

    If you mean previously in VS, VS can keep several Console windows open without closing any one of them, but now, in VS 2022, VS only keeps one Console window open, then you may need to refer to this thread: Visual Studio 2022 on Windows 11 reuses the same console window on successive runs, overwriting the previous output.

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

    One workaround => creating and using shortcut keys to run the project by executing external tools.

    If you mean for only one console window, it opens and automatically closes after clicking Start Without Debugging, then like what David mentioned above, by default, in VS 2022, the Console window should not be closed automatically. For different type of projects, the settings are different. You can reset VS General settings by following steps here: Reset all settings.

    Besides, as VS 2022 uses Microsoft Visual Studio Debug Console, you can try to generate a profile(refer to this thread: Microsoft Visual Studio 2022 Debug Console instead of cmd.exe), but probably it doesn’t work.

    Sincerely,

    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.


  2. Igor Pavlov 0 Reputation points
    2023-12-28T12:14:42.8833333+00:00

    @David Lowndes

    Oddly, the behaviour you describe is the opposite I normally have.

    It's important to note that my project is fully built by an external build system (Bazel). That build system creates some stub projects for the VS to manage the code. I don't know what this project type is but it's not a VS native console app project, however its behavior is similar to the native project.

    For your project, what do you have for the Linker, System, SubSystem setting?

    May I ask you to be more specific on the options? How do these settings are mapped to the command line options?

    For me, a console project has Console (/SUBSYSTEM:CONSOLE)

    I've checked the Subsystem field of the IMAGE_OPTIONAL_HEADER32 structure from the output exe and it has the IMAGE_SUBSYSTEM_WINDOWS_CUI (3) value.


  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    11 deleted comments

    Comments have been turned off. Learn more

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.