Restore locked mode fails on error NU1004: The packages lock file is inconsistent

Viewed 544

I have 2 C# projects: Project.csproj and Project.Tests.csproj.

Project.Tests.csproj contains ProjectReference:

<ItemGroup>
    <ProjectReference Include="../Project/Project.csproj" />
</ItemGroup>

I use floating versions of dependencies and I also enabled lock files:

<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
<RestoreLockedMode>false</RestoreLockedMode>

When I execute dotnet restore --locked-mode, I'm getting

/usr/share/dotnet/sdk/3.1.409/NuGet.targets(128,5): error NU1004: 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.

When I try suggestion dotnet restore --force-evaluate, it is restored correctly, there are no changes to lock files though. Funnily enough, when I execute dotnet restore --locked-mode right after, it fails on the same error NU1004

Do you have any idea how to overcome this issue? Is there a way to tell NuGet to provide more descriptive information why it fails?

0 Answers
Related