NuGet packages.lock.json out of date with RestoreLockedMode in CI
With RestoreLockedMode=true, restore fails instead of silently updating packages.lock.json when the lock no longer matches the project. This catches dependency drift, but the lockfile must be regenerated and committed to fix it.
What this error means
restore in CI fails with "The packages lock file is inconsistent with the project" or "Nothing to do. None of the projects specified contain packages to restore" after a reference change, because locked mode forbids updating the lock.
error NU1004: The packages lock file is inconsistent with the project dependencies
so restore can't be run in locked mode. Disable the RestoreLockedMode MSBuild property
or pass an explicit --force-evaluate option to run restore to update the lock file.Common causes
Dependencies changed without relocking
A PackageReference was added, removed, or bumped, but packages.lock.json was not regenerated, so the committed lock is stale.
The lockfile was not committed with the change
The reference edit landed without the updated lockfile, so locked-mode CI sees a mismatch.
How to fix it
Regenerate and commit the lockfile
- Run restore with force-evaluate locally to refresh the lock.
- Commit the updated
packages.lock.json. - Re-run CI; locked mode now matches the project.
dotnet restore --force-evaluate
git add **/packages.lock.jsonKeep locked mode on in CI
Restore with --locked-mode in CI so drift fails fast instead of silently changing versions.
dotnet restore --locked-modeHow to prevent it
- Regenerate
packages.lock.jsonwhenever references change. - Commit the lockfile in the same change as the reference edit.
- Enable RestoreLockedMode in CI to catch drift early.