2

I am new to dot.net core and tried the sample, dotnet new, dotnet restore, dotnet run.

After 2nd step(dotnet restore), I tried to delete this lock file, then "dotnet run" fails, as it says it needs a lock file. Why did Microsoft design such a "lock" file and why does the "run" command require such a lock file?

If this lock file is designed to prevent multiple processes to build the project, then it only has to be an empty file, act as a "lock". But in fact, this file is quite large, compared with other source code.

lorond
  • 3,856
  • 2
  • 37
  • 52
Troskyvs
  • 7,537
  • 7
  • 47
  • 115
  • Making .NETCore run on Unix operating system inevitably introduces [unix-like artifacts](http://unix.stackexchange.com/questions/12815/what-are-pid-and-lock-files-for). – Hans Passant Jul 15 '16 at 09:40
  • 5
    Possible duplicate of [What is project.lock.json?](http://stackoverflow.com/questions/38065611/what-is-project-lock-json) – Nate Barbettini Jul 15 '16 at 23:26

2 Answers2

8

If you look at the lock file, you'll see that it contains details of the exact version of each dependency that was restored, transitively. This "locks" that set of versions until dotnet restore is run again.

I believe the aim at least was to allow developers to decide whether or not to check project.lock.json files into source control, giving more control over exactly when updated dependencies would be used. I think there's still some debate about when/whether that's a good idea.

It also allows multiple tools to look at the dependency graph directly, without needing to compute it again (in a possibly unstable way, if dependencies change).

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • I now get the error on `dotnet restore`. How's that possible? – mbob Feb 23 '17 at 09:50
  • @mbob: I suggest you ask a new question with your project.json (or better, a minimal one that still demonstrates the problem) and the exact error you're getting. Make sure you give details about the version of .NET Core SDK you're using too, given that new versions use csproj instead of project.json – Jon Skeet Feb 23 '17 at 10:31
1

there are differences. If you examine the contents of the file, you’ll see that it includes a complete list of all of the NuGet packages the app is using. This isn’t necessarily the same as what is included in project.json, because project.json can use wildcards and be vague about its versions (e.g. 1.0.0.*). It’s also much more complete than project.json, since it includes all of the libraries included in the frameworks specified in project.json. Here’s a small extract from a project.json.lock file:

taken from: https://blog.falafel.com/what-is-project-lock-json/

                   "locked": false,
                   "version": -9996,
                   "targets": {
                "DNX,Version=v4.5.1": {
                  "Microsoft.AspNet.DataProtection.Abstractions/1.0.0-beta5": {
                    "dependencies": {
                      "Microsoft.Framework.Runtime.Abstractions": "1.0.0-beta5"
                    },
                    "frameworkAssemblies": [
                      "mscorlib",
                      "System",
                      "System.Core",
                      "Microsoft.CSharp"
                    ],
                    "compile": {
                      "lib/dnx451/Microsoft.AspNet.DataProtection.Abstractions.dll": {}
                    },
                    "runtime": {
                      "lib/dnx451/Microsoft.AspNet.DataProtection.Abstractions.dll": {}
                    }
                  }
Frank Alvaro
  • 468
  • 4
  • 12