项目清单中的 dependencies 属性是一个 JSON 对象,可将包名称映射到版本。版本号指示要从包注册表下载包的哪个版本。例如:
{
"dependencies": {
"com.my-package": "2.3.1",
"com.my-other-package": "1.0.1-preview.1",
etc.
}
}
除了使用版本号之外,Package Manager 还支持通过以下内容来添加项目依赖关系:
直接依赖关系是项目级别的依赖关系。通过 Package Manager 窗口来安装包或手动编辑项目的 manifest.json
文件以显式添加依赖关系时,您将创建直接包依赖关系 ():
包可以声明自身对其他包的依赖关系。当您安装包时,此类包依赖关系将成为项目的间接 () 依赖关系,也称为传递性依赖关系。
Package Manager 会确定要安装包的哪个版本(无论包将成为项目的直接依赖项还是间接依赖项)。为此,Package Manager 将优先考虑直接依赖关系,然后才考虑间接依赖关系,但前提是更高优先级的版本不违反任何其他要求。
这种评估称为依赖关系解析,大致遵循以下逻辑:
在任何情况下,都可以手动覆盖这些解决策略。为此,请在项目清单中请求特定版本(通过从 Package Manager 窗口进行安装或通过直接编辑清单)。这将创建直接依赖关系,其优先级高于任何解决策略。
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.