如何强制降级 dotnet 核心中的传递依赖

ala*_*ree 3 c# nuget .net-core

我的应用程序 A 依赖于 nuget 库 B 和使用 csproj 中的 PackageReference 的 nuget 库 C 版本 1.1.1。

<PackageReference Include="B" Version="1.0.0" />
<PackageReference Include="C" Version="1.1.1" />
Run Code Online (Sandbox Code Playgroud)

但是,库 B 依赖于库 C >= 1.1.2。

<PackageReference Include="C" Version="1.1.2" />
Run Code Online (Sandbox Code Playgroud)

我无法更改我的应用程序以在 C 版本 1.1.2 上运行,并且我知道 B 可以在 C 版本 1.1.1 上正常工作。

如何强制我的应用程序 A 使用 C 版本 1.1.1 运行?具体来说,我需要删除编译器错误 CS1705。以前在完整框架中,我会使用绑定重定向,但我知道这些在 dotnet 核心中不可用。

A
- B
- C (v = 1.1.1)


B
- C (v >= 1.1.2)
Run Code Online (Sandbox Code Playgroud)

Jim*_*mex 5

我不确定这是否会解决您的 CS1705 问题,但是要为包 C 提供 1.1.1 的确切版本,那么您将使用Version Ranges

例如。 <PackageReference Include="C" Version="[1.1.1]" />

您还可以尝试使用隐式版本控制,让构建过程为您决定。您Version将从中删除该属性<PackageReference />

例如。 <PackageReference Include="C" />