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.
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.
dotnet restore --force-evaluate
git add **/packages.lock.jsonClear caches and restore clean
When restore inputs are stale, wipe the local caches and restore fresh.
dotnet nuget locals all --clear
dotnet restoreHow to prevent it
- Run
dotnet restore --force-evaluateafter changing package references. - Commit a consistent
packages.lock.jsonand keep it in sync. - Use
--locked-modein CI to catch lock drift before it becomes a restore error.