NuGet Error NU1004

Scenario 1

The project target frameworks are different than the lock file's target frameworks. Lock file target frameworks: net6.0,net5.0. Project target frameworks net6.0. The packages lock file is inconsistent with the project dependencies so restore can't be run in locked mode. Disable the RestoreLockedMode MSBuild property or pass an explicit --force-evaluate option to run restore to update the lock file.

Issue

When restore is run in locked mode, it ensures that the project dependencies have not changed since the last restore. A new framework, net5.0 has been added to the project.

Solution

Consult the recommendations in the error message and do one of the following:

  • Rerun restore without locked mode to regenerate the lock file.
  • Return the project to it's previous state, removing the additional net5.0 framework.

Scenario 2

The package reference Contoso.Library version has changed from [2.0.0, ) to [1.2.3, ).The packages lock file is inconsistent with the project dependencies so restore can't be run in locked mode. Disable the RestoreLockedMode MSBuild property or pass an explicit --force-evaluate option to run restore to update the lock file.

Issue

When restore is run in locked mode, it ensures that the project dependencies have not changed since the last restore. Contoso.Library's version has been changed from 2.0.0 to 1.2.3.

Solution

Consult the recommendations in the error message and do one of the following:

  • Rerun restore without locked mode to regenerate the lock file.
  • Return the project to it's previous state, changing the version back to 2.0.0.