Skip to content

Fix error attribution for invalid TargetFramework and Version during restore - #7342

Merged
nkolev92 merged 6 commits into
devfrom
dev-nkolev92-sna
May 19, 2026
Merged

nkolev92 merged 6 commits into
devfrom
dev-nkolev92-sna

Conversation

@nkolev92

@nkolev92 nkolev92 commented Apr 29, 2026 •

Copy link
Copy Markdown
Member

Bug

Fixes: NuGet/Home#12470
Fixes: NuGet/Home#13772
Fixes: NuGet/Home#11230
Fixes: NuGet/Home#14605

Description

When PackageSpec creation fails because of invalid project data, restore can attribute the error to the wrong project (or the solution) and skip writing the failing project's assets file.

This change routes those failures through AdditionalMessages in both static graph and non-static graph restore so the generated NU1105 is attached to the project that actually failed.

It also preserves invalid semicolon-delimited target framework strings long enough for downstream validation, which fixes cases like net10.0;net8.0.

Tests

Added integration tests in DotnetRestoreTests.cs:

Test Scenarios Static Graph Non-Static Graph
ProjectReferencesProjectWithInvalidTargetFramework empty, invalid, net8.0;net472 ✅ ✅
ProjectWithBadVersion 1.0.badversion ✅ ✅
ProjectWithInvalidNuGetVersion 3.1.3a1 ✅ ✅
SolutionWithProjectWithInvalidTargetFramework empty, invalid, net8.0;net472 ✅ ✅
SolutionWithCPMBadPackageVersion 1.0.badversion in Directory.Packages.props ✅ ✅
CPMProjectWithSemicolonInTargetFramework net10.0;net8.0 with CPM (#14605) ✅ ✅

All tests validate:

  • Error is attributed to the correct project file (not the solution or a referencing project)
  • Full localized error messages using resource strings (Strings.Error_ReadingProjectInformation, Strings.SpecValidationInvalidFramework)
  • Assets file presence or absence depending on the error path

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@nkolev92
nkolev92 force-pushed the dev-nkolev92-sna branch 2 times, most recently from 41f1ef7 to 48781d4 Compare April 29, 2026 15:27
@nkolev92
nkolev92 force-pushed the dev-nkolev92-sna branch 2 times, most recently from 588e107 to 9c2814d Compare May 13, 2026 18:28
@nkolev92
nkolev92 force-pushed the dev-nkolev92-sna branch from 9c2814d to 4f2dca9 Compare May 13, 2026 18:29
@nkolev92
nkolev92 marked this pull request as ready for review May 13, 2026 20:13
@nkolev92
nkolev92 requested a review from a team as a code owner May 13, 2026 20:13
@nkolev92

Copy link
Copy Markdown
Member Author

@zivkan Pushed some more changes.

Tests should hopefully pass again.

@nkolev92
nkolev92 requested a review from zivkan May 14, 2026 01:10
- Add usePackageSpecFactory parameter to all 6 new tests per review comment
- Add environmentVariables parameter to RestoreProject/SolutionExpectFailure/Success helpers
- Fix null PackagesPath crash in error specs by using string.Empty
- Fix GetTargetFrameworkStrings to not split TargetFramework (singular) by semicolons,
  aligning with RestoreProjectAdapter.Prepare() behavior in the new path

Co-authored-by: Copilot <[email protected]>
@nkolev92
nkolev92 enabled auto-merge (squash) May 18, 2026 15:49
@nkolev92
nkolev92 requested a review from jeffkl May 18, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants