问题描述
我按照说明创建新的 .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.
我的问题:
- 我的假设是否正确?
- 是否可以通过删除不需要的 NuGet 包/依赖项来简化我的应用程序?
- 怎么样?
推荐答案
更新:project.json
已替换为 .csproj
作为.NET Standard 项目的主项目文件.这个问题指的是引入之前的旧系统NuGet 4.0 中的包引用.
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
作为构建过程的工件,但应该忽略它.管理 .NET Standard/.NET Core 项目所依赖的 NuGet 包应始终由以下任一方式完成
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,请使用包管理器 GUI
旧答案供后代参考: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 restore
) 期间,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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!