Skip to content

Option to explicitly ignore packages.lock.json file when present on disk #51938

@GauteAtSemine

Description

@GauteAtSemine

We are requesting a documented feature or MSBuild property that allows users to explicitly ignore an existing packages.lock.json file during the NuGet restore process.

Scenario

We operate projects in two distinct modes:

  1. "Package Mode": The default, where a committed packages.lock.json file is used to lock internal, floating-version package references, ensuring deterministic historical builds.
  2. "Project Mode": A specific Condition (detected by solution name) where we switch from PackageReference to ProjectReference for internal dependencies (e.g., in a monolith or Aspire application). In this mode, the lock file should be entirely ignored, as direct project references supersede it.

Problem

In previous tooling versions, simply not defining RestorePackagesWithLockFile allowed us to ignore the on-disk lock file seamlessly. In recent .NET SDK and NuGet versions, the presence of a packages.lock.json file automatically triggers validation and modification (adding "type": "Project" entries) during the solution restore phase in Visual Studio and the CLI. This breaks our mode-switching capability and pollutes the repository with unwanted file changes.

Desired Behavior

We require a reliable mechanism (an MSBuild property like <NuGetIgnoreLockFile>true</NuGetIgnoreLockFile>) to disable the lock file feature entirely for a specific restore operation, even if the packages.lock.json file exists on disk.

This would allow us to restore the previous seamless behavior using existing MSBuild property conditions (Directory.Build.props), avoiding complex file-renaming hacks or wrapper scripts that fall outside of standard Microsoft tooling and IDE integration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions