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.
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).
See more on this question at Stackoverflow