锁定文件包含 Package Manager 对于一个项目的依赖解析结果。Package Manager 在解析包依赖图时使用锁文件来提供确定性的结果。当 Unity Package Manager 计算出一个成功的解析结果时,它会将该解析结果存储在项目的 Packages
文件夹中的一个名为 packages-lock.json
的 JSON 文件中。对项目清单或可变包清单的任何修改(嵌入式或者从本地文件夹安装) 可能会迫使 Package Manager 重新计算已解析的包版本。但是只要锁定文件中的包版本满足依赖版本及解析策略涵盖的范围,该软件包将保持锁定在该版本。
例如,这是锁定文件中的一个典型条目:
"com.unity.textmeshpro": {
"version": "2.0.1",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.ugui": "1.0.0"
},
"url": "https://packages.unity.com"
},
etc.
当 Package Manager 解决任何冲突的间接依赖时,它会尝试重用尽可能多的锁定包。这保证了后续的依赖解析对相同的依赖项集合产生相同的结果。它还最大限度地减少了耗时的操作,例如下载、解压缩或复制包。
如果没有仅包含锁定包的解决方案,Package Manager 选择升级风险最小的解决方案,补丁升级优先于次要或主要版本升级,次要版本升级优先于主要版本升级。事实上,您可以自定义升级的风险级别。有关更多信息,请参阅自定义解析策略。
要强制刷新间接依赖项版本,请删除锁定文件。
不要手动修改锁定文件:Package Manager 创建并维护锁定文件,因此它会覆盖您对文件所做的任何更改。
将锁定文件置于源代码控制之下,以便您可以一致重现相同的包集,以确保您的项目随着时间的推移和在不同的机器上保持一致。
默认情况下,Package Manager 在成功计算依赖图时创建或更新锁定文件。如果您看到意外结果,您可以在项目清单中将 enableLockFile 属性设置为 false
以禁用锁定。但是,如果禁用锁定文件,Package Manager 会再次克隆 Git URL 包,这会导致性能下降和额外的网络使用。如果您在两次解析之间将较新的提交推送到远程 Git 代码仓库,也可能导致不确定的结果。
*SAT 解算器功能添加于 Unity 2019.4 NewIn20194
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.