[dotnet watch] Fix device prompt hang for MAUI workload projects#54392
Open
jonathanpeppers wants to merge 1 commit into
Open
[dotnet watch] Fix device prompt hang for MAUI workload projects#54392jonathanpeppers wants to merge 1 commit into
jonathanpeppers wants to merge 1 commit into
Conversation
When a multi-TFM project uses conditionally-imported workload targets (e.g., MAUI), the ComputeAvailableDevices target is only available in TFM-specific inner builds. The previous code checked the outer project (rootProject.Targets) which has no TargetFramework set, so the conditional import never fires and device selection was skipped. This caused the child dotnet-run process to show its own device prompt, creating a stdin race with dotnet-watch's Console.ReadKey() loop that made the prompt hang. Fix: after TFM selection, look up the TFM-specific inner project node from the ProjectGraph and check its targets for ComputeAvailableDevices. Added DotnetRunDevicesWorkload test asset that simulates MAUI workload behavior with a conditionally-imported Devices.targets file. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a dotnet watch hang when a device-selection prompt follows a target-framework-selection prompt for MAUI/workload-style projects where ComputeAvailableDevices is only available in TFM-specific inner builds (conditional workload imports).
Changes:
- Updates device-selection gating logic to check the selected TFM’s inner project node for
ComputeAvailableDevices. - Adds a new test asset that simulates workload conditional imports of device targets.
- Expands integration + unit test coverage for “TFM prompt → device prompt” interactive flows.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/TestAssets/TestProjects/DotnetRunDevicesWorkload/Program.cs | New test app that prints selected device/RID (via generated DeviceInfo) to validate prompt flow. |
| test/TestAssets/TestProjects/DotnetRunDevicesWorkload/DotnetRunDevicesWorkload.csproj | New multi-TFM test project; conditionally imports device targets to mimic MAUI workload behavior. |
| test/TestAssets/TestProjects/DotnetRunDevicesWorkload/Devices.targets | Provides ComputeAvailableDevices/DeployToDevice targets only when imported in inner builds. |
| test/dotnet-watch.Tests/HotReload/MauiHotReloadTests.cs | Adds integration tests covering sequential TFM + device prompt flow, including workload-conditional target scenario. |
| test/dotnet-watch.Tests/HotReload/BuildParametersSelectionPromptTests.cs | Adds unit test verifying Spectre prompt flow remains functional across multiple sequential prompts. |
| src/Dotnet.Watch/Watch/HotReload/HotReloadDotNetWatcher.cs | Switches device-selection check to use the selected TFM’s project graph node so workload targets are visible. |
This was referenced May 21, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug where
dotnet watch's device selection prompt hangs when it appears as the second prompt after a target framework prompt, specifically for MAUI workload projects.Root Cause
For multi-TFM MAUI projects, the
ComputeAvailableDevicesMSBuild target is defined in workload.targetsfiles that are only imported whenTargetFrameworkis set (via a conditional<Import>). Whendotnet watchloads the project graph with a null TFM to discover available frameworks, the outer multi-TFM project doesn't haveTargetFrameworkset, so the workload import never fires andComputeAvailableDevicesis not visible.The old code checked
rootProject.Targets.ContainsKey(ComputeAvailableDevices)on this outer project, found nothing, and skipped device selection entirely. The childdotnet runprocess (which runs with a specific TFM) then discovered the target and showed its own device prompt. This created a stdin race betweendotnet watch'sConsole.ReadKey()loop and the child process's Spectre.Console prompt, causing the hang.Fix
After TFM selection, use
projectGraph.TryGetProjectNode(path, targetFramework)to look up the TFM-specific inner project node (which has the conditional imports resolved) and check its targets forComputeAvailableDevices.Testing
DotnetRunDevicesWorkloadtest asset that simulates MAUI workload behavior with a conditionally-importedDevices.targetsfileSelectsFrameworkThenDeviceintegration test (passes with unconditional targets)SelectsFrameworkThenDevice_WorkloadConditionalTargetintegration test (hangs without fix, passes with fix)SelectsFrameworkThenDeviceunit test for the prompt flow