Proj0043: Use lock files

By default, the package versions specified by either the PackageReference or PackageVersion are used as constraints for which dependency versions are allowed to be used when building the project. This means that the resolved package versions might change over time, leading to non-reproducible builds or security issues.

In order to prevent these issues, it is advisable to enable .NET’s lock files (similar to npm’s package-lock.json) when building your production code. This requires setting the RestorePackagesWithLockFile property to true, and ensuring that locked mode is enabled when building for production.

See also:

Non-compliant

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>

</Project>

Compliant

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
  </PropertyGroup>

</Project>