[dotnet run] Fix NETSDK1005 when project refs different TFMs#53523
Merged
jonathanpeppers merged 1 commit intorelease/10.0.3xxfrom Mar 20, 2026
Merged
[dotnet run] Fix NETSDK1005 when project refs different TFMs#53523jonathanpeppers merged 1 commit intorelease/10.0.3xxfrom
NETSDK1005 when project refs different TFMs#53523jonathanpeppers merged 1 commit intorelease/10.0.3xxfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes dotnet run restore behavior during device discovery so TargetFramework does not cascade into referenced projects (preventing corrupted project.assets.json and subsequent NETSDK1005 when app/project refs target different TFMs), and adds regression coverage.
Changes:
- Update
RunCommandSelector.TryComputeAvailableDevicesto run restore using aProjectInstancecreated withoutTargetFramework. - Cache/reuse a pre-
TargetFrameworkproject/collection when the framework is selected interactively, avoiding unnecessary reloads. - Add Windows-only regression tests (explicit
--frameworkand auto-selected framework) plus a new test asset reproducing the scenario.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Cli/dotnet/Commands/Run/RunCommandSelector.cs | Runs restore for device discovery without TargetFramework to avoid cascading into referenced projects. |
| test/dotnet.Tests/CommandTests/Run/GivenDotnetRunBuildsCsProj.cs | Adds regression tests for the dotnet run scenario (explicit and implicit framework selection). |
| test/TestAssets/TestProjects/RunWindowsAppWithLibRef/App/App.csproj | New repro asset: multi-TFM app with ComputeAvailableDevices target and a project reference. |
| test/TestAssets/TestProjects/RunWindowsAppWithLibRef/App/Program.cs | Prints output from referenced library to validate successful run. |
| test/TestAssets/TestProjects/RunWindowsAppWithLibRef/SharedLib/SharedLib.csproj | New repro asset: non-platform TFM library. |
| test/TestAssets/TestProjects/RunWindowsAppWithLibRef/SharedLib/Helper.cs | Library helper returning a known string for test validation. |
Fixes: #53488 `TryComputeAvailableDevices` was running restore with `$(TargetFramework)` as a global MSBuild property, which cascaded to dependency projects and corrupted their project.assets.json (e.g. restoring a `net10.0` library for `net10.0-windows`). Add `CreateRestoreProjectInstance()` that provides a `ProjectInstance` *without* `TargetFramework` for restore, matching `RestoringCommand` behavior. When `TargetFramework` is selected interactively, the pre-TF project is reused. When `--framework` is explicit, a temporary one is created lazily. Created tests for both scenarios: `--framework` and automatic selection.
7da571e to
172aa86
Compare
rolfbjarne
approved these changes
Mar 19, 2026
MiYanni
approved these changes
Mar 19, 2026
This was referenced Mar 20, 2026
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.
Fixes: #53488
TryComputeAvailableDeviceswas running restore with$(TargetFramework)as a global MSBuild property, which cascaded to dependency projects and corrupted theirproject.assets.json(e.g. restoring anet10.0library fornet10.0-windows).Add
CreateRestoreProjectInstance()that provides aProjectInstancewithoutTargetFrameworkfor restore, matchingRestoringCommandbehavior. WhenTargetFrameworkis selected interactively, the pre-TF project is reused. When--frameworkis explicit, a temporary one is created lazily.Created tests for both scenarios:
--frameworkand automatic selection.