Skip to content

Stop Dependabot's restore rewriting multi-targeted lock files - #73

Merged
brandonifco merged 1 commit into
mainfrom
fix/dependabot-lock-files
Sep 15, 2026
Merged

brandonifco merged 1 commit into
mainfrom
fix/dependabot-lock-files

Conversation

@brandonifco

Copy link
Copy Markdown
Owner

Closes #63.

Root cause, from dependabot-core's source (NuGetUpdater.Core/Discover/SdkProjectDiscovery.cs): discovery runs dotnet msbuild <project> /t:Restore,ResolveProjectReferences,GenerateBuildDependencyFile /p:ProjectReferenceBuildTargets="Restore;...". MSBuild calls each referenced multi-targeted project with a single TargetFramework, so NuGet rewrote its packages.lock.json for that framework alone.

Reproduced locally: running that exact invocation from a test project on a clean tree strips net8.0 from the lock files of RulesKernel, RulesKernel.Randomness and RulesKernel.Testing. That matches #42 and #45.

Fix: Directory.Build.targets sends the lock file to obj/ when a multi-targeted project is restored under a single TargetFramework. Ordinary dotnet restore never evaluates that combination.

  • The reproduction now changes 0 lock files (3 without the fix).
  • A clean dotnet restore --locked-mode still fails with NU1004 on a lock file missing net8.0, so the gate isn't blinded.
  • validate.sh full passes.

Kept fixed: tools/lockfile-probe/check.sh runs the reproduction from every test project in a copy of the tree, and fails if any lock file changes. It runs in validate.sh full (~8 s). It fails without the fix, as shown above.

We'll only see it end to end when Dependabot next opens a NuGet PR.

🤖 Generated with Claude Code

Dependabot's NuGet discovery invokes Restore through
ProjectReferenceBuildTargets, so each referenced multi-targeted project was
restored with one TargetFramework and its packages.lock.json rewritten with
net10.0 only. That broke both Dependabot NuGet PRs (#42, #45).

Reproduced locally with the same msbuild invocation (from dependabot-core's
SdkProjectDiscovery.cs): three lock files lost net8.0. Directory.Build.targets
sends the lock file to obj/ when a multi-targeted project is restored under a
single TargetFramework, which ordinary restore never does. With it, the
reproduction changes nothing; a fresh locked restore still fails on a lock
file missing a framework. tools/lockfile-probe/check.sh runs the reproduction
in validate.sh full and fails without the fix.

Closes #63

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@brandonifco
brandonifco merged commit b153645 into main Sep 15, 2026
1 check passed
@brandonifco
brandonifco deleted the fix/dependabot-lock-files branch September 15, 2026 20:21
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.

Dependabot NuGet updates drop net8.0 from multi-targeted lock files

1 participant