Skip to content
Latchkey

NuGet "error NU1004" - Restore Failed in CI

NuGet reported an NU1004 restore error - the restore did not produce a consistent assets/lock state, so the build cannot proceed. It is a restore-stage failure, not a compiler error.

What this error means

Restore (or the restore phase of build) fails with error NU1004 and a message about the lock file or restore inputs being inconsistent. It is deterministic for a given project state until the lock/assets are reconciled.

dotnet restore output
error NU1004: The packages lock file is inconsistent with the project dependencies
so restore can't be run in locked mode.

Common causes

Lock file inconsistent with the project

A packages.lock.json that no longer matches the PackageReference set fails restore (especially under locked mode), surfacing as NU1004.

Stale or missing restore inputs

A partially generated assets file or a lock that was not regenerated after a dependency change leaves restore in an inconsistent state.

How to fix it

Regenerate the lock file

Re-evaluate the graph to refresh the lock, then commit it.

Terminal
dotnet restore --force-evaluate
git add **/packages.lock.json

Clear caches and restore clean

When restore inputs are stale, wipe the local caches and restore fresh.

Terminal
dotnet nuget locals all --clear
dotnet restore

How to prevent it

  • Run dotnet restore --force-evaluate after changing package references.
  • Commit a consistent packages.lock.json and keep it in sync.
  • Use --locked-mode in CI to catch lock drift before it becomes a restore error.

Frequently asked questions

What causes ""error NU1004""?
A packages.lock.json that no longer matches the PackageReference set fails restore (especially under locked mode), surfacing as NU1004.
How do I fix "error NU1004"?
Re-evaluate the graph to refresh the lock, then commit it.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card