Using ASP.NET Core 1.0, is it best practice to check in the project.lock.json file into 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.
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.
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).
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.
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
dotnet restore
and in most cases will be different than the version stored in source control. So it will be modified in almost every commitActually you do want to commit your project.lock.json in git sometimes.
For the exact reasons that, it shows you the dependencies you have used. Say:
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 of checking in this file is you might get allot of merge conflicts on continues updates of packages.
Use only hard version dependencies (this is quite hard though for nuget). And only manually update to newer version once in a while.
dotnet restore
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With