I have an issue in which the lock file generated by visual studio differs from the lock file generated by nuget.exe. This causes the error I get during a CI build:
NU1004: The packages lock file is inconsistent with the project dependencies so restore can't be run in locked mode. When I run a build in visual studio and having the lock file enabled, some project references have a different key. With visual studio, they are called "[productname].[component]", while doing the same using nuget.exe they are called "[companyname].[productname].[componentname]".
NuGet product used:
Nuget command line tool: 5.4.0.6315
VS version: 16.5.3
OS version: Windows 10
I was unable to reproduce it with a small repro solution. But in our case
NuGet Version: 5.4.0.6315
MSBuild P2P timeout [ms]: 120000
MSBuild auto-detection: using msbuild version '16.5.0.12403' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin\msbuild.exe "C:\Users\
Running restore with 8 concurrent jobs.
Reading project file
Persisting no-op dg to
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.
Committing restore...
Writing cache file to disk. Path:
Writing packages lock file at disk. Path:
Restore failed in 78,05 ms for
@PaulVrugt Can you try restoring your project using the latest nuget.exe preview version available at nuget.org/downloads? Can you run with detailed logging and setting the NUGET_SHOW_STACK environment variable to "true"?
$env:NUGET_SHOW_STACK="true"
nuget.exe restore solution.sln -LockedMode -verbosity detailed
@dominoFire Thank you for the quick reply! I've tested it with the latest nuget preview, but the result is the same:
PS C:\Users\[user]\source\repos\[product]> $env:NUGET_SHOW_STACK="true"
PS C:\Users\[user]\source\repos\[product]> c:\nuget\preview\nuget.exe restore testing\***.***.web.tests\***.***.Web.Tests.vbproj -LockedMode -ConfigFile Website\nuget.config -verbosity detailed
NuGet Version: 5.6.0.6489
MSBuild P2P timeout [ms]: 120000
MSBuild auto-detection: using msbuild version '16.5.0.12403' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin\msbuild.exe "C:\Users\[user]\AppData\Local\Temp\NuGetScratch\bhwlobox.btc.nugetinputs.targets" /t:GenerateRestoreGraphFile /nologo /nr:false /v:q /p:NuGetRestoreTargets="C:\Users\[user]\AppData\Local\Temp\NuGetScratch\vtspnsit.e1o.nugetrestore.targets" /p:RestoreUseCustomAfterTargets="True" /p:RestoreTaskAssemblyFile="C:\nuget\preview\nuget.exe" /p:RestoreConfigFile="Website\nuget.config" /p:RestoreLockedMode="True"
Running restore with 8 concurrent jobs.
Reading project file C:\Users\[user]\source\repos\[product]\testing\***.***.web.tests\***.***.Web.Tests.vbproj.
The restore inputs for '***.***.Web.Tests' have changed. Continuing restore.
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.
Committing restore...
Assets file has not changed. Skipping assets file writing. Path: C:\Users\[user]\source\repos\[product]\testing\***.***.web.tests\obj\project.assets.json
Writing cache file to disk. Path: C:\Users\[user]\source\repos\[product]\testing\***.***.web.tests\obj\project.nuget.cache
Writing packages lock file at disk. Path: C:\Users\[user]\source\repos\[product]\testing\***.***.web.tests\packages.lock.json
Persisting dg to C:\Users\[user]\source\repos\[product]\testing\***.***.web.tests\obj\***.***.Web.Tests.vbproj.nuget.dgspec.json
Restore failed in 110,46 ms for C:\Users\[user]\source\repos\[product]\testing\***.***.web.tests\***.***.Web.Tests.vbproj.
NuGet Config files used:
C:\Users\[user]\source\repos\[product]\Website\nuget.config
Feeds used:
https://pkgs.dev.azure.com/***code/_packaging/Shared/nuget/v3/index.json
Hey @PaulVrugt
Any chance you can give us a repro?
This error can happen for so many different reasons, and unfortunately our error https://github.com/NuGet/Home/issues/7696 is not great at this point, so a repro is one of our only means for investigation.
@nkolev92
Yep, I've been able to repro it.
steps:
It seems that nuget create a lock file with the assemblyname of the referenced assembly in it, and visual studio creates a lock file with the name of the projectfile. This causes the restore issue. You can see this, if you add the -ForceEvaluate flag to the nuget command and check the generated lockfile
Thanks,
I can repro and I've updated the title to reflect the exact issue.
Hi. I've also just encountered it. Are there any workarounds or estimations available?
I'm running into the same problem. When interacting with nuget through Visual Studio (16.8.4) the packages.lock.json file is rewritten changing CompanyName.Project.Name into project.name, causing build/restore issues. The workaround I've been working with thus far is running nuget restore -LockedMode -ForceEvaluate in the solution folder.
Most helpful comment
Hi. I've also just encountered it. Are there any workarounds or estimations available?