External terminal not registering Ctrl+C with .NET Core
See original GitHub issue- VSCode Version: 1.38.1
- OS Version: Win10 (10.0.17763)
The following used to work in .NET Core 2.2 app with a debug profile for the externalTerminal
in earlier versions of VSC (or OmniSharp if that’s where the problem actually lies here), but it doesn’t work with new 3.0 framework bits and the latest public VSC.
Debug a .NET Core app in the externalTerminal
using either the Microsoft.NET.Sdk.Web
or Microsoft.NET.Sdk.Worker
project SDK that calls UseConsoleLifetime on the host builder so that the app should listen for Ctrl+C
to stop the app. The app doesn’t stop.
Steps to Reproduce:
-
Create a .NET Core console app with UseConsoleLifetime …
public class Program { public static async Task Main(string[] args) { using (var host = Host.CreateDefaultBuilder(args) .UseConsoleLifetime() .Build()) { // Start the host await host.StartAsync(); // Wait for the host to shutdown await host.WaitForShutdownAsync(); } } }
The preceding code works if the app is run with
dotnet run
in a command shell … -
Use a console debugger profile and run the same app in the
externalTerminal
…{ "version": "0.2.0", "configurations": [ { "name": ".NET Core Launch (console)", "type": "coreclr", "request": "launch", "preLaunchTask": "build", "program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/ConsoleSample.dll", "args": [], "cwd": "${workspaceFolder}", "stopAtEntry": false, "console": "externalTerminal" } ] }
The app will not respond to
Ctrl+C
. In prior versions (.NET Core 2.2),Ctrl+C
would work when using theexternalTerminal
in this scenario.
I asked ASP.NET Core engineering, and they thought it might be on the VSC-side of the equation given that Ctrl+C
works when the app is run in a command shell. See item response 4 at https://github.com/aspnet/AspNetCore.Docs/issues/12841#issuecomment-533206352.
I put up a repro project at https://github.com/guardrex/ConsoleSample.
The sample app that I put up also has a keystroke-monitoring service that logs presses of the w
key. That code works. Running in the externalTerminal
, the app reports that it hears the w
key clicks, while the app doesn’t respond to Ctrl+C
. Sure, the app could listen for Ctrl+C
there and shut the app down, but that’s not the point … that would be a hack. UseConsoleLifetime
should work the way that this app works in a normal command shell (I think 😄).
Does this issue occur when all extensions are disabled? That can’t be checked because the configured debug type is coreclr
, which isn’t supported without either (or both) C# OmniSharp. In fact, I’m not sure if this bug report should be filed here or over on https://github.com/OmniSharp/omnisharp-vscode.
Issue Analytics
- State:
- Created 4 years ago
- Comments:20 (8 by maintainers)
Top GitHub Comments
@guardrex you can download the zip, close all your current windows and then open the zip executable. If you try running the 64-bit version while the other is running it will probably just open another 32-bit window.
I can repro this, but have no idea why it is happening. Simple program:
Running the same command that VS Code is running from a cmd.exe instance manually, it works fine. But in an external terminal, no SIGINT is sent.