NuGet解决了错误的包依赖版本

And*_*und 6 .net nuget

所以我有一个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'.
Run Code Online (Sandbox Code Playgroud)

如您所见,我得到4.5.0版本的依赖项.

nuget doco中它说:

如果未安装依赖项,NuGet将执行以下步骤:

NuGet枚举了版本规范中的Feed中的每个Subkismet版本.然后NuGet缩小设置为具有最低主要/次要版本的包.在其余的软件包中,NuGet选择版本号最高的软件包.

"NuGet选择版本号最高的那个." 似乎在这里违反了,因为从来没有版本.

这是NuGet中的错误吗?

Xav*_*ter 9

您引用的依赖项解析的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


Ram*_*its 5

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

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

<configuration>
    <config>
        <add key="DependencyVersion" value="HighestPatch" />
    </config>
</configuration>
Run Code Online (Sandbox Code Playgroud)

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

%AppData%\Nuget\NuGet.Config
Run Code Online (Sandbox Code Playgroud)

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

文档还说:

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

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

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

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