Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is project.lock.json?

I followed the instruction to create new .NET Core project and ran this from cmd:

dotnet new dotnet restore 

The second statement creates project.lock.json that contains a lot of garbage (not really garbage but tons of dependencies, configurations etc.). I assume these dependencies is .NET framework that is broken down into separate NuGet packages.

My questions:

  1. Is my assumption correct?
  2. Can I make my application lighter by removing not needed NuGet packages/dependencies?
  3. How?
like image 314
Andrei Avatar asked Jun 28 '16 01:06

Andrei


People also ask

What is json lock file?

json file, which is much more common and has been around for much longer. The goal of package-lock. json file is to keep track of the exact version of every package that is installed so that a product is 100% reproducible in the same way even if packages are updated by their maintainers.

Is it OK to delete package lock json?

json that result in two different installs. You may have noticed it before; you install a package using npm and suddenly a new file called package-lock. json appears in your project directory. Don't delete that package-lock file, run npm install and regenerate it!

What is project json?

Project. json is an automatically generated file which is included in the folder of each automation project made in Studio. The file holds information about the project dependencies, and web services loaded in libraries.

Do I need a package lock json?

If you're collaborating on a shared project with multiple developers, and you want to ensures that installations remain identical for all developers and environments, you need to use package-lock. json . package-lock. json is automatically generated for any operations where npm modifies either package.


2 Answers

Update: project.json has been replaced with .csproj as the main project file for .NET Standard projects. This question refers to the old system before the introduction of PackageReference in NuGet 4.0.

You may still occasionally see project.lock.json as an artifact of the build process, but it should be ignored. Managing the NuGet packages that your .NET Standard/.NET Core project depends on should always be done by either

  • Editing the .csproj file directly
  • Using the dotnet CLI (dotnet add package, etc)
  • Using the Package Manager GUI if you're using Visual Studio

Old answer for posterity: project.lock.json is generated by the .NET tooling when you restore the project's packages. You shouldn't touch it or check it into source control. Edit project.json directly.

During the package restore process (dotnet restore), NuGet has to analyze the dependencies in your project, walk their dependency graphs, and figure out what packages should be installed for your project and your project's dependencies.

This is a non-trivial amount of work, so the results are cached in project.lock.json to make subsequent restores faster and more efficient. The lock file will be regenerated if project.json is modified and dotnet restore is executed again.

like image 150
Nate Barbettini Avatar answered Oct 18 '22 00:10

Nate Barbettini


Every so often, in our team, when someone updates some nuget, we have the same problem, the lock.json files doens't get updated, even running dotnet restore so, before applying the last choice (deleting them) I suggest run grunt from your command line. If that doesn't work, delete all the lock.json files and run dotnet restore, this is my favourite choice ;)

like image 42
Francisco Avatar answered Oct 17 '22 23:10

Francisco