Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should project.lock.json file be checked into source control? (ASP.NET Core 1.0)

Tags:

asp.net

Using ASP.NET Core 1.0, is it best practice to check in the project.lock.json file into source control?

like image 845
Ender2050 Avatar asked Jul 19 '16 02:07

Ender2050


People also ask

Does package lock json need to be in source control?

json intact. It is highly recommended you commit the generated package lock to source control: this will allow anyone else on your team, your deployments, your CI/continuous integration, and anyone else who runs npm install in your package source to get the exact same dependency tree that you were developing on.

Why should you check in package lock json?

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. This solves a very specific problem that package. json left unsolved.

Should package lock json be committed yarn?

json should only be committed to the source code version control when the project cannot be a dependency of other projects, i.e. package-lock. json should only by committed to source code version control for top-level projects (programs consumed by the end user, not other programs).

What is project lock json?

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.


2 Answers

Short answer: No, project.lock.file should not be checked into source control - you should configure the version control system to ignore it (i.e. add it to .gitignore if you're using git).

Long answer: The project.lock.json contains a snapshot of project's whole dependency tree - not just packages listed in "dependencies" sections, but also all resolved dependencies of those dependencies, and so on. But it is not like ruby's Gemfile.lock. Unlike Gemfile.lock, project.lock.json doesn't tell dotnet restore which exact versions of packages should be restored - it simply gets overwritten. As such, it should be treated like a cache file and never be checked into source control.

If you check it into version control, then most probably on other machine:

  • dotnet will think that all packages are restored, but in fact some packages might be missing and the build will fail, without hinting the developer to run dotnet restore
  • project.lock.json will be overwritten during dotnet restore and in most cases will be different than the version stored in source control. So it will be modified in almost every commit
  • project.lock.json will cause conflicts during merge
like image 172
qbik Avatar answered Oct 09 '22 09:10

qbik


Actually you do want to commit your project.lock.json in git sometimes.

Checking your project json

For the exact reasons that, it shows you the dependencies you have used. Say:

  1. Me as a developer works on an application, i hate every time updating packages so i add a package dependency to nuget package X = 1.*
  2. I restore package i get version 1.2.4
  3. The package maker just made a very stupid mistake, he broke something while just trying to make a fix and release 1.2.5
  4. Person 2 checks out (or even worse release build kicks in).
  5. Person 2 restores and gets version 1.2.5
  6. Person 2 runs your application and find the application is broken.
  7. Person 2 starts debugging and thinks there must be a bug in the software.

At this step 7 Person 2 could have seen in git that his lock file was changed and a newer version of a library has been downloaded, Which has not been tested by any of the other developers!

Downsides

Downsides of checking in this file is you might get allot of merge conflicts on continues updates of packages.

Alternative solution

Use only hard version dependencies (this is quite hard though for nuget). And only manually update to newer version once in a while.

Downsides

  • This doesn't work if you build a library for other people to use, since you pin them to a certain version of your dependencies.
  • Dependencies of dependencies still get resolved automatically so if you don't specify them yourself you can't guarantee there version on dotnet restore

Conclusion

If you want to avoid 'Works on my machine' quotes and the hell of constantly manually updating to newer version: Checking the project.lock.json.

And also build a CI/Release build check to test if this file wasn't changed compared to git, before you release (If your software is very critical)!

If this is not a problem and also automatically updating (to a potentially broken package) is not a big problem, you might not want to commit your project.lock.json.

like image 26
Joel Harkes Avatar answered Oct 09 '22 08:10

Joel Harkes