.NET › Assemblies & NuGet
What is a NuGet lock file (packages.lock.json), and what problem does it solve for reproducible builds?
IntermediateAnswer
A lock file records the exact resolved version of every direct and transitive dependency at restore time, ensuring that subsequent restores (across different machines, CI runs, or dates) produce bit-for-bit identical dependency trees rather than potentially resolving to newer compatible versions that happen to be available -- critical for reproducible builds and catching unexpected dependency changes in code review.
<PropertyGroup>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
# Generates packages.lock.json, committed to source control
# dotnet restore --locked-mode fails the build if resolution would differ from the lock fileReal-world example A CI pipeline runs `dotnet restore --locked-mode` to guarantee that a build today resolves the exact same dependency versions as it did when the lock file was last committed, catching any unexpected drift immediately.