【问题标题】:NuGet resolves the wrong version of package dependencyNuGet 解决包依赖的错误版本
【发布时间】:2014-04-30 18:37:13
【问题描述】:

所以我有一个包 NServiceBus.Host,它依赖于 NServiceBus >= 4.5.0。

在 nuget 上有一个 4.5.1 版本的 NServiceBus。当我安装包 NServiceBus.Host 我得到:

PM> install-package nservicebus.host
Attempting to resolve dependency 'NServiceBus (≥ 4.5.0)'.
Attempting to resolve dependency 'NServiceBus.Interfaces (≥ 4.5.0)'.
Installing 'NServiceBus.Interfaces 4.5.0'.
You are downloading NServiceBus.Interfaces from NServiceBus Ltd, the license agreement to which is available at http://particular.net/LicenseAgreement. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'NServiceBus.Interfaces 4.5.0'.
Installing 'NServiceBus 4.5.0'.

如你所见,我得到了 4.5.0 版本的依赖项。

nuget doco 中声明:

如果没有安装依赖,NuGet会经过以下 步骤:

NuGet 会枚举订阅源中的每个版本的 Subkismet 在版本规范中。 NuGet 然后将该设置范围缩小为 具有最低主要/次要版本的软件包。剩下的 包,NuGet 会选择版本号最高的包。

“NuGet 选择版本号最高的那个。”这里似乎违反了,因为有一个 never 版本。

这是 NuGet 中的错误吗?

【问题讨论】:

  • 如果您在倒数第二段重新引用文档的一部分时,您错过了一点:“在其余包中,NuGet 选择版本号最高的包” - 可能是 NuGet 存储库中更高的版本号,但这不是您的包或其依赖项引用的最高版本号。
  • 但在这种情况下,4.5.0 和 4.5.1 都应该包含在剩余的软件包中,对吧?

标签: .net nuget


【解决方案1】:

您提到的有关依赖项解析的 NuGet 文档自 2010 年 12 月以来未更新。真正的 NuGet 文档可在此处获得:https://docs.nuget.org

此外,默认情况下,NuGet 将解析允许范围内的最低 major.minor 版本,如包依赖项中所定义。所以 4.5.0 是正确的默认依赖解析。

自 NuGet v2.8.1 以来的新功能:您可以使用 NuGet 包管理器控制台使用备用依赖项解析算法:

Install-Package NServiceBus.Host -DependencyVersion HighestPatch

还有更多选项,请在此处查看文档: https://docs.nuget.org/docs/reference/package-manager-console-powershell-reference#Install-Package

【讨论】:

  • 谢谢,我们可以期待HighestPatch成为未来的默认策略吗?
  • 只能用 Powershell 指定吗?我在常规命令提示符上看不到该选项。
  • 有没有类似的策略来强制HighestMinor?我的意思是根据 semver 它们是兼容的,那么为什么有人想要最旧的版本?
  • 哦,我要学会阅读!它在doco中, - HighestMinor:具有最低主要,最高次要,最高补丁的版本;
  • @AndreasÖhlund 如果只有所有包作者都能正确使用 SemVer,那么它可能是一个很好的默认值。但是 SemVer 并不是万无一失的,它只是一种“陈述意图”的方式,它不是精确的科学。因此,NuGet 现在更好地保持安全,并允许消费者做出决定:)
【解决方案2】:

正如 Xavier 所说,这似乎是默认行为。但是,文档说您可以通过编辑 nuget 配置来更改默认行为:

指定要从有效依赖包列表中选择的依赖包的版本。默认值为最低。您可以通过在 nuget.config 文件中指定新的默认值来覆盖此默认值:

<configuration>
    <config>
        <add key="DependencyVersion" value="HighestPatch" />
    </config>
</configuration>

我按照文档中的描述编辑了我的配置文件:

%AppData%\Nuget\NuGet.Config

然后它可以在 Powershell 中运行,但不能在常规命令提示符下运行。

文档还说:

奇怪的是,文档说 2.7.2 之前的默认值是 HighestPatch...

注意,对于 NuGet 2.7.2 或更早版本,默认值为 HighestPatch,并且无法更改。

2.8 的发行说明提到了行为的变化,以及安装包现在随着时间的推移具有一致的依赖关系解析结果的原因。

https://docs.nuget.org/docs/release-notes/nuget-2.8

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-29
    • 2021-10-13
    • 2021-09-28
    • 2021-12-18
    • 1970-01-01
    • 2019-03-15
    • 1970-01-01
    相关资源
    最近更新 更多