dotnet / project-system

The .NET Project System for Visual Studio
MIT License
959 stars 386 forks source link

Add launch profile option to use integrated terminal #9353

Open drewnoakes opened 6 months ago

drewnoakes commented 6 months ago

Today, when launching a console app, a new terminal window is opened.

VS has an integrated terminal that appears within a tool window.

The debugging infrastructure supports a launch option to do this. We just need to plumb it through from the UI, to launchSettings.json, to the launch invocation.

We might also want to add an option (Tools|Options) that controls the default value for when the property is not present in the launchSettings.json.

For an example of integrating this feature, see https://devdiv.visualstudio.com/DevDiv/_git/WebTools/pullrequest/425844?_a=files&path=/src/ProjectSystem/Web/WebServer/SelfHostWebServer.cs (MS internal).

drewnoakes commented 5 months ago

Sharing some findings.

Enabling this feature is straightforward:

diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ProjectLaunchTargetsProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ProjectLaunchTargetsProvider.cs
index 1c095a8fb..7cada1fa0 100644
--- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ProjectLaunchTargetsProvider.cs
+++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ProjectLaunchTargetsProvider.cs
@@ -360,7 +360,8 @@ private async Task<bool> IsIntegratedConsoleEnabledAsync()
             {
                 if (await IsIntegratedConsoleEnabledAsync())
                 {
-                    settings.LaunchOptions |= DebugLaunchOptions.IntegratedConsole;
+                    const int DBGLAUNCH_UseIntegratedTerminalService = 0x20000000;
+                    settings.LaunchOptions |= DebugLaunchOptions.IntegratedConsole | (DebugLaunchOptions)DBGLAUNCH_UseIntegratedTerminalService;
                 }

                 useCmdShell = UseCmdShellForConsoleLaunch(resolvedProfile, settings.LaunchOptions);

The result is this:

image

Despite it being easy to turn this feature on, there are a few open questions:

Overall, I like the idea of adding this but we will need to work through the above issues with other teams before we can ship this.

drewnoakes commented 5 months ago

CPS PR to add DebugLaunchOptions member: https://dev.azure.com/devdiv/DevDiv/_git/CPS/pullrequest/524465

drewnoakes commented 5 months ago

Feature request for this on developer community: https://developercommunity.visualstudio.com/t/display-c-console-app-output-in-internal-terminal/1224895