Skip to content

[dotnet run] Fix NETSDK1005 when project refs different TFMs#53523

Merged
jonathanpeppers merged 1 commit intorelease/10.0.3xxfrom
dev/peppers/fix-dotnet-run-restore
Mar 20, 2026
Merged

[dotnet run] Fix NETSDK1005 when project refs different TFMs#53523
jonathanpeppers merged 1 commit intorelease/10.0.3xxfrom
dev/peppers/fix-dotnet-run-restore

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

@jonathanpeppers jonathanpeppers commented Mar 18, 2026

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.

Copilot AI review requested due to automatic review settings March 18, 2026 18:53
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 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.TryComputeAvailableDevices to run restore using a ProjectInstance created without TargetFramework.
  • Cache/reuse a pre-TargetFramework project/collection when the framework is selected interactively, avoiding unnecessary reloads.
  • Add Windows-only regression tests (explicit --framework and 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.

Comment thread src/Cli/dotnet/Commands/Run/RunCommandSelector.cs Outdated
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.
@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/fix-dotnet-run-restore branch from 7da571e to 172aa86 Compare March 18, 2026 20:50
@jonathanpeppers jonathanpeppers merged commit 6e321aa into release/10.0.3xx Mar 20, 2026
28 checks passed
@jonathanpeppers jonathanpeppers deleted the dev/peppers/fix-dotnet-run-restore branch March 20, 2026 01:28
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.

4 participants