.net 什么是project.lock.json?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38065611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 09:49:05  来源:igfitidea点击:

What is project.lock.json?

.net.net-coreproject.json

提问by Andrei

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

我按照说明创建新的 .NET Core 项目并从 cmd 运行:

dotnet new
dotnet restore

The second statement creates project.lock.jsonthat 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.

第二个语句创建project.lock.json包含大量垃圾(不是真正的垃圾,而是大量的依赖项、配置等)。我假设这些依赖项是 .NET 框架,它被分解为单独的 NuGet 包。

My questions:

我的问题:

  1. Is my assumption correct?
  2. Can I make my application lighter by removing not needed NuGet packages/dependencies?
  3. How?
  1. 我的假设正确吗?
  2. 我可以通过删除不需要的 NuGet 包/依赖项来简化我的应用程序吗?
  3. 如何?

回答by Nate Barbettini

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

更新project.json已被替换.csproj为 .NET Standard 项目的主项目文件。这个问题是指在 NuGet 4.0引入PackageReference之前的旧系统。

You may still occasionally see project.lock.jsonas 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

您可能偶尔仍会将其project.lock.json视为构建过程的工件,但应将其忽略。管理 .NET Standard/.NET Core 项目所依赖的 NuGet 包应始终由以下任一方式完成

  • Editing the .csprojfile directly
  • Using the dotnet CLI(dotnet add package, etc)
  • Using the Package Manager GUI if you're using Visual Studio
  • .csproj直接编辑文件
  • 使用dotnet CLIdotnet add package等)
  • 如果您使用的是 Visual Studio,则使用包管理器 GUI


Old answerfor posterity: project.lock.jsonis 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.jsondirectly.

后代的旧答案project.lock.json由 .NET 工具在您恢复项目的包时生成。您不应该触摸它或将其签入源代码管理。project.json直接编辑。

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

在包还原过程 ( dotnet restore) 中,NuGet 必须分析项目中的依赖项,遍历它们的依赖关系图,并找出应该为项目安装哪些包以及项目的依赖项。

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

这是一项非常重要的工作,因此结果会被缓存,project.lock.json以使后续恢复更快、更高效。如果project.json被修改并dotnet restore再次执行,锁文件将重新生成。

回答by xisket

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 restoreso, before applying the last choice (deleting them) I suggest run gruntfrom your command line. If that doesn't work, delete all the lock.json files and run dotnet restore, this is my favourite choice ;)

每隔一段时间,在我们的团队中,当有人更新一些 nuget 时,我们会遇到同样的问题,lock.json 文件不会更新,甚至运行dotnet restore所以,在应用最后一个选择(删除它们)之前,我建议运行grunt从你的命令行。如果这不起作用,请删除所有 lock.json 文件并运行dotnet restore,这是我最喜欢的选择;)