Skip to content

[dotnet watch] Fix device prompt hang for MAUI workload projects#54392

Open
jonathanpeppers wants to merge 1 commit into
release/10.0.4xxfrom
jonathanpeppers/fix-watch-device-prompt-hang
Open

[dotnet watch] Fix device prompt hang for MAUI workload projects#54392
jonathanpeppers wants to merge 1 commit into
release/10.0.4xxfrom
jonathanpeppers/fix-watch-device-prompt-hang

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

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 ComputeAvailableDevices MSBuild target is defined in workload .targets files that are only imported when TargetFramework is set (via a conditional <Import>). When dotnet watch loads the project graph with a null TFM to discover available frameworks, the outer multi-TFM project doesn't have TargetFramework set, so the workload import never fires and ComputeAvailableDevices is not visible.

The old code checked rootProject.Targets.ContainsKey(ComputeAvailableDevices) on this outer project, found nothing, and skipped device selection entirely. The child dotnet run process (which runs with a specific TFM) then discovered the target and showed its own device prompt. This created a stdin race between dotnet watch's Console.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 for ComputeAvailableDevices.

Testing

  • Added DotnetRunDevicesWorkload test asset that simulates MAUI workload behavior with a conditionally-imported Devices.targets file
  • Added SelectsFrameworkThenDevice integration test (passes with unconditional targets)
  • Added SelectsFrameworkThenDevice_WorkloadConditionalTarget integration test (hangs without fix, passes with fix)
  • Added SelectsFrameworkThenDevice unit test for the prompt flow

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>
@jonathanpeppers jonathanpeppers requested a review from tmat as a code owner May 20, 2026 20:16
Copilot AI review requested due to automatic review settings May 20, 2026 20:16
@jonathanpeppers jonathanpeppers requested a review from a team as a code owner May 20, 2026 20:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants