Adding a project reference in Visual Studio when using lock file (package.lock.json)

I have a solution with many .net framework 4.8 projects and some .net standard projects. We recently added lockfiles to the projects. Projects have RestoreLockedMode property set to true.

When updating/installing nuget package, the lockfiles are automatically updated as needed.

The problem is, when I add a project reference to a project, the lock file is not updated, resulting in a NU1004 error.

Currently my workaround is building with command line setting RestoreLockedMode=false :

msbuild.exe ./mysolution.sln -t:restore,build -p:RestoreLockedMode=false

with this line, packages lock are updated. Is there a way Visual Studio could do the job when adding the reference ? The command line works, but it’s far from optimal when 40 diffent dev works on the project, and not everyone understantds what’s going on.

Leave a Comment