什么是project.lock.json? [英] What is project.lock.json?

查看:212
本文介绍了什么是project.lock.json?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

dotnet new
dotnet restore

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

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

我的问题:


  1. 我的假设正确吗?

  2. 我可以通过删除不需要的NuGet软件包/依赖项来简化我的应用程序吗?

  3. 如何?


推荐答案

更新 project.json 已替换为 .csproj 作为.NET Standard项目的主要项目文件。此问题涉及引入 NuGet 4.0中的PackageReference

Update: project.json has been replaced with .csproj as 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.lock.json 构建过程的工件,但是应该忽略它。

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


  • 编辑 .csproj 文件直接

  • 使用 dotnet CLI dotnet添加软件包等)

  • 如果您使用的是Visual Studio,请使用Package Manager GUI

  • Editing the .csproj file directly
  • Using the dotnet CLI (dotnet add package, etc)
  • Using the Package Manager GUI if you're using Visual Studio

后代: project.lock.json 由.NET工具在还原项目的程序包时生成。您不应该触摸它或将其检入源代码管理。直接编辑 project.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. Edit project.json directly.

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

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

这是一笔不小的工作,因此将结果缓存在 project.lock.json 中,以使后续还原更快且更高效。如果修改 project.json 并再次执行 dotnet restore ,将重新生成锁定文件。

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

这篇关于什么是project.lock.json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆