NU1107 dotnet build_error ai_generated true

错误 NU1107: 检测到 'PackageA' 的版本冲突。引用包: PackageB 2.0.0 -> PackageA (>= 1.5.0), PackageC 3.0.0 -> PackageA (>= 2.0.0)。

error NU1107: Version conflict detected for 'PackageA'. Reference packages: PackageB 2.0.0 -> PackageA (>= 1.5.0), PackageC 3.0.0 -> PackageA (>= 2.0.0).

ID: dotnet/nuget-package-version-conflict

其他格式: JSON · Markdown 中文 · English
85%修复率
88%置信度
1证据数
2023-06-20首次发现

版本兼容性

版本状态引入弃用备注
5.0 active
6.0 active
7.0 active
8.0 active
9.0 active

根因分析

NuGet 包版本冲突发生在依赖关系图中不同包要求相同包的不兼容版本时,导致构建失败。

English

NuGet package version conflict occurs when different packages in the dependency graph require incompatible versions of the same package, causing the build to fail.

generic

官方文档

https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu1107

解决方案

  1. 在项目文件中添加绑定重定向或使用特定版本的 PackageReference。示例:<PackageReference Include="PackageA" Version="2.0.0" /> 并确保所有依赖包更新到兼容版本。
  2. 使用 'dotnet nuget why' 命令分析依赖树。示例:dotnet nuget why PackageA
  3. 将所有包更新到最新的兼容版本:dotnet list package --outdated 然后 dotnet update package

无效尝试

常见但无效的做法:

  1. Manually editing the .csproj file to force a specific version of PackageA without considering transitive dependencies 65% 失败

    Forcing a version may break other packages that depend on a different version, leading to runtime errors or further conflicts.

  2. Removing one of the conflicting packages entirely from the project 50% 失败

    Removing a package may remove required functionality, causing build errors or missing method exceptions.

  3. Running 'dotnet restore --force' without resolving the version mismatch 80% 失败

    Restore only re-downloads packages; it does not resolve version conflicts unless package versions are explicitly aligned.