dotnet watch: Ctrl+C during a build is ignored on SDK 10.0.303 (works on 9.0.317)
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
### Describe the bug
When dotnet watch is in the middle of a rebuild triggered by a file change, pressing Ctrl+C has no effect. The build runs to completion, the application relaunches, and the shutdown request is discarded. Pressing Ctrl+C repeatedly during the build does not help.
Ctrl+C works correctly when the application is idle and fully started, it is specifically a Ctrl+C that arrives while a build is in flight that gets lost.
This is a regression. The same solution on SDK 9.0.317 terminates as expected when Ctrl+C is pressed during a build.
Note that the .NET 10 watcher is used even for net9.0 projects, because the highest installed SDK provides dotnet watch. Pinning via global.json is currently the only workaround we have found.
### Steps to reproduce
Solution layout: five projects (one ASP.NET Core web project targeting net9.0, four class libraries). Roughly 1500 watched files.
```
dotnet watch run --no-hot-reload -- --urls https://*:8080 --verbose
Wait for the app to fully start (Application started. Press Ctrl+C to shut down.)
Save a watched .cs file to trigger a rebuild
While Building... is displayed, press Ctrl+C
```
### Expected behavior
dotnet watch terminates. This is what SDK 9.0.317 does:
```
dotnet watch ⌚ Exited with error code -1
dotnet watch ⌚ File changed: ...\ProTAK.Common\Legacy\ClassLib\ProgramInit.cs
Using launch settings from ...\Properties\launchSettings.json...
Building...
dotnet watch ⌚ Shutdown requested. Press Ctrl+C again to force exit.
dotnet watch ⌚ Exited with error code -1
PS D:\...>
```
### Actual behavior
On SDK 10.0.303, the build completes, the application relaunches, and dotnet watch keeps running. The shutdown request is never acted on. Subsequent Ctrl+C presses during the same build have no effect either.
Once the app has fully restarted, a further Ctrl+C does work, so the watcher's console handler is still functioning; the request made during the build is simply dropped.
It looks as though a queued restart takes precedence over a pending shutdown, and the build stage does not observe the cancellation.
### Is this a regression?
_No response_
### Are there any workarounds?
_No response_
### dotnet --info output
```console
```
### IDE version
_No response_
### Other details
_No response_
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce with `dotnet watch run --no-hot-reload` using the five-project solution, then focus on the console Ctrl+C handling, queued restart, and build stage described in the report. Compare SDK 10.0.303 with 9.0.317 and verify that Ctrl+C during “Building...” causes shutdown before the application relaunches.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100