Skip to content

[release/11.0.2xx] [dotnet watch] Use the selected device's RuntimeIdentifier when evaluating and building projects - #57234

Open
jonathanpeppers wants to merge 1 commit into
release/11.0.2xxfrom
jonathanpeppers-backport-56723-release-11-0-2xx
Open

jonathanpeppers wants to merge 1 commit into
release/11.0.2xxfrom
jonathanpeppers-backport-56723-release-11-0-2xx

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Backport of #56723 to release/11.0.2xx.

Manual backport, because the automatic backport had conflicts (#56723 (comment)).

Differences from the original PR

  • release/11.0.2xx does not have the change that escapes the Device MSBuild property value. This backport passes the device name without escaping, as this branch does now.
  • The SingleProject_DeviceIdIsEscaped test is not included, because it tests that escaping change.

Original description

An iOS project can default to a simulator RID, such as iossimulator-arm64. If the user selects a physical iPhone in dotnet watch, restore and build use ios-arm64, but watch keeps the project graph it evaluated before selection. Watch then reads files, such as the Hot Reload WebSocket key, from the simulator's obj directory.

  • Reload the project graph with the selected Device and RuntimeIdentifier when they differ from the evaluated values. Keep the selection for later graph reloads and rebuilds.
  • Add DeviceId to carry the device name and its RID together.
  • Build projects one at a time when a device RID is set. Solution builds do not accept a global RID (NETSDK1134).
  • When rebuilding a dependency, pass the device RID only if the dependency is a runnable application.
  • Add _IsRunnableApplication to Microsoft.NET.Sdk.targets and use it in the IsRidAgnostic calculation. IsRidAgnostic behavior does not change.

…dentifier` when evaluating/building projects (#56723)

An iOS project can default to a simulator RID, such as `iossimulator-arm64`. If the user selects a physical iPhone in `dotnet watch`, restore and build use `ios-arm64`, but watch keeps the project graph it evaluated before selection. Watch then reads files, such as the Hot Reload WebSocket key, from the simulator's `obj` directory.

### Changes

- Reload the project graph with the selected `Device` and `RuntimeIdentifier` when they differ from the evaluated values. Keep the selection for later graph reloads and rebuilds.
- Add `DeviceId` to carry the device name and its RID together.
- Build projects one at a time when a device RID is set. Solution builds do not accept a global RID (NETSDK1134).
- When rebuilding a dependency, pass the device RID only if the dependency is a runnable application. A library builds without a RID, as it does when the app builds it.
- Add `_IsRunnableApplication` to `Microsoft.NET.Sdk.targets` and use it in the `IsRidAgnostic` calculation. Watch reads this property instead of duplicating the logic. `IsRidAgnostic` behavior does not change.

Backport of #56723. The Device value is not escaped, because the MSBuild property escaping change is not in this branch.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers
jonathanpeppers requested review from a team and tmat as code owners November 19, 2026 21:15
Copilot AI balanced review requested due to automatic review settings November 19, 2026 21:15
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Incorrect runtime-identifier handling causes Hot Reload dependency output paths to diverge from actual builds, while missing framework selection can prevent valid multi-targeted dependencies from rebuilding.

3 open issues
What changed in this PR

Backports the dotnet watch device-RID fix to release/11.0.2xx, aligning project evaluation with the selected device’s build outputs. It intentionally preserves this branch’s existing unescaped device-name handling.

Changes:

  • Carries device identity and RID together through graph evaluation, builds, and launches.
  • Builds projects individually when a device RID is set and adjusts dependency rebuild handling.
  • Adds regression coverage for device selection, output paths, and dependency builds.
File Description
test/​dotnet-watch.Tests/​HotReload/​BuildProjectsTests.cs Adds device-RID and dependency rebuild tests.
src/​Tasks/​Microsoft.NET.Build.Tasks/​targets/​Microsoft.NET.Sdk.targets Extracts _IsRunnableApplication for watch to consume.
src/​Dotnet.Watch/​Watch/​UI/​DeviceInfo.cs Clarifies selection-display documentation only.
src/​Dotnet.Watch/​Watch/​Process/​ProjectLauncher.cs Reads launch device and RID from DeviceId.
src/​Dotnet.Watch/​Watch/​HotReload/​HotReloadDotNetWatcher.cs Propagates device properties through evaluation and rebuilds.
src/​Dotnet.Watch/​Watch/​Context/​ProjectOptions.cs Replaces separate device fields with DeviceId.
src/​Dotnet.Watch/​Watch/​Context/​DeviceId.cs Adds the device identity and optional RID value type.
src/​Dotnet.Watch/​Watch/​Build/​ProjectGraphFactory.cs Accepts additional graph evaluation properties.
src/​Dotnet.Watch/​Watch/​Build/​BuildNames.cs Adds shared device, RID, and runnable-property names.
src/​Dotnet.Watch/​dotnet-watch/​Watch/​BuildEvaluator.cs Reads the device name from the new value type.
src/​Dotnet.Watch/​dotnet-watch/​CommandLine/​CommandLineOptions.cs Converts the command-line device into DeviceId.

Review effort: Balanced

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants