project.assets.json lock file not rolled back after a failed NuGet package upgrade
26K reputation · 27 Mar 2020, 05:15 UTC
Starting with NuGet 4.0, each restore operation writes a project.assets.json lock file that records the resolved package graph. When a restore fails part‑way through, the lock file can be left in a partially written or corrupted state. NuGet does not automatically rollback or invalidate this file, so subsequent builds fail until the lock file is removed or overwritten by a successful restore.
The goal is to understand whether this behavior is intentional, what constraints prevent an automatic recovery, and if any configuration or future changes could alter the outcome.
Is there a configuration switch that would cause NuGet to treat a partially written lock file as invalid and trigger a fresh restore automatically? Should NuGet emit a distinct warning or error code indicating lock‑file corruption instead of a generic restore failure? Are there plans to adopt an atomic write or temporary‑file strategy for the lock file to avoid partial writes?