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

- **ID:** `dotnet/nuget-package-version-conflict`
- **领域:** dotnet
- **类别:** build_error
- **错误码:** `NU1107`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 5.0 | active | — | — |
| 6.0 | active | — | — |
| 7.0 | active | — | — |
| 8.0 | active | — | — |
| 9.0 | active | — | — |

## 解决方案

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
   ```

## 无效尝试

- **Manually editing the .csproj file to force a specific version of PackageA without considering transitive dependencies** — Forcing a version may break other packages that depend on a different version, leading to runtime errors or further conflicts. (65% 失败率)
- **Removing one of the conflicting packages entirely from the project** — Removing a package may remove required functionality, causing build errors or missing method exceptions. (50% 失败率)
- **Running 'dotnet restore --force' without resolving the version mismatch** — Restore only re-downloads packages; it does not resolve version conflicts unless package versions are explicitly aligned. (80% 失败率)
