Repository navigation
[release/11.0.2xx] [dotnet watch] Use the selected device's RuntimeIdentifier when evaluating and building projects - #57234
Conversation
…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>
|
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. |
There was a problem hiding this comment.
🟡 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
MiYanni
left a comment
There was a problem hiding this comment.
🤖Copilot🤖
Thanks for doing the manual backport. I compared it against the merged #56723 (6f145b44): the src/ changes are identical apart from the Device escaping difference called out in the description, and the tests match minus SingleProject_DeviceIdIsEscaped. So the backport itself is faithful. My concern is whether this should ship on release/11.0.2xx before one known gap is resolved.
1. Library output paths in the Hot Reload graph now diverge from the real build (servicing risk).
This was raised in this thread, and the reply confirms that the graph gives a RID-agnostic library a RID-specific output path. The Hot Reload impact was deferred without a repro or a tracking issue. I don't think it is safe to defer on a release branch:
- Before this change, the app's default RID (for example
iossimulator-arm64) came from a local project property, so it never flowed to referenced libraries. Library nodes in the graph were RID-less and matched whatdotnet buildproduced. - After this change, every device that reports a RID triggers a graph reload with a global
RuntimeIdentifier(line 1137). That includes the common simulator case where the RID equals the project default. Static graph propagates that global to everyProjectReference. The real build drops it for RID-agnostic references (IsRidAgnostic/GlobalPropertyFlowTests.TestGlobalPropertyFlowToLibrary). ManagedCodeWorkspacefeeds these graphProjectInstances straight intoHotReloadMSBuildWorkspace(ManagedCodeWorkspace.cs:33,CreateProjectInstanceMap). The library projects' compilation output (DLL/PDB) paths will point atobj/<cfg>/<tfm>/<rid>/directories that the build never writes. Roslyn's EnC needs those outputs for the baseline and for PDB checksum matching, so library edits may be rejected or silently ignored.FilePathExclusions(FilePathExclusions.cs:42-43) and static web asset manifest lookup for RCLs (EvaluationResult.cs:176-178) use the same paths.
That means this PR could regress library Hot Reload on the simulator path that works today, in exchange for fixing the physical-device path. Could you either:
- validate library-edit Hot Reload end to end on an iOS simulator and an Android device with a
ProjectReference'd class library (and add a test that asserts a referenced RID-agnostic library node'sTargetPath/IntermediateOutputPathmatches the path the app build uses), or - fix the per-reference RID flow in
mainfirst and include it here, or at minimum file a tracking issue and get explicit sign-off from the area owners that the trade-off is acceptable for this branch?
2. The other two deferred threads (multi-targeted dependency lookup with a null or app TFM, and _IsRunnableApplication not capturing an explicit RID policy) are pre-existing or edge cases, and I'm fine deferring them. A tracking issue linked from this PR would make sure they don't get lost.
3. CI. dotnet-sdk-public-ci shows about 1,090 Helix failures. They look unrelated (NU1903 advisory warnings for Microsoft.DotNet.ILCompiler polluting stdout assertions, and no watch tests among the displayed failures), and later release/11.0.2xx PRs such as #57373 are green on a newer base. Please rebase or re-run so this merges on a clean signal.
Minor: _IsRunnableApplication is now computed unconditionally in Microsoft.NET.Sdk.targets, even when IsRidAgnostic is set explicitly. That's harmless as written, but it's a shared-targets change on a release branch, so please mention it in the risk notes.
|
|
||
| // Reevaluate with the selected Device and RuntimeIdentifier as global properties, | ||
| // so that RID-specific outputs and imports flow to referenced projects. | ||
| projectGraph = TryLoadProjectGraph(targetFramework, device, cancellationToken); |
There was a problem hiding this comment.
🤖Copilot🤖
This makes RuntimeIdentifier a graph-wide global property whenever the selected device reports a RID, including when it equals the project's default (for example, simulator). Static graph propagates it to every referenced library, unlike the real build, which strips it for RID-agnostic references. The Hot Reload workspace consumes these nodes, so library DLL/PDB paths no longer match the build. Before this change, the simulator case kept library nodes RID-less. Please validate library-edit Hot Reload here, or scope the RID to the nodes whose build actually receives it.
|
I'm going to fix some issues discovered in this change for main first. |


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.2xxdoes not have the change that escapes theDeviceMSBuild property value. This backport passes the device name without escaping, as this branch does now.SingleProject_DeviceIdIsEscapedtest 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 indotnet watch, restore and build useios-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'sobjdirectory.DeviceandRuntimeIdentifierwhen they differ from the evaluated values. Keep the selection for later graph reloads and rebuilds.DeviceIdto carry the device name and its RID together._IsRunnableApplicationtoMicrosoft.NET.Sdk.targetsand use it in theIsRidAgnosticcalculation.IsRidAgnosticbehavior does not change.