NU1107
dotnet
build_error
ai_generated
true
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
85%Fix Rate
88%Confidence
1Evidence
2023-06-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 5.0 | active | — | — | — |
| 6.0 | active | — | — | — |
| 7.0 | active | — | — | — |
| 8.0 | active | — | — | — |
| 9.0 | active | — | — | — |
Root Cause
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中文
NuGet 包版本冲突发生在依赖关系图中不同包要求相同包的不兼容版本时,导致构建失败。
Official Documentation
https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu1107Workarounds
-
90% success Add a binding redirect or use a PackageReference with a specific version in the project file. Example: <PackageReference Include="PackageA" Version="2.0.0" /> and ensure all dependent packages are updated to compatible versions.
Add a binding redirect or use a PackageReference with a specific version in the project file. Example: <PackageReference Include="PackageA" Version="2.0.0" /> and ensure all dependent packages are updated to compatible versions.
-
75% success Use the 'dotnet nuget why' command to analyze the dependency tree. Example: dotnet nuget why PackageA
Use the 'dotnet nuget why' command to analyze the dependency tree. Example: dotnet nuget why PackageA
-
85% success Update all packages to their latest compatible versions using: dotnet list package --outdated then dotnet update package
Update all packages to their latest compatible versions using: dotnet list package --outdated then dotnet update package
中文步骤
在项目文件中添加绑定重定向或使用特定版本的 PackageReference。示例:<PackageReference Include="PackageA" Version="2.0.0" /> 并确保所有依赖包更新到兼容版本。
使用 'dotnet nuget why' 命令分析依赖树。示例:dotnet nuget why PackageA
将所有包更新到最新的兼容版本:dotnet list package --outdated 然后 dotnet update package
Dead Ends
Common approaches that don't work:
-
Manually editing the .csproj file to force a specific version of PackageA without considering transitive dependencies
65% fail
Forcing a version may break other packages that depend on a different version, leading to runtime errors or further conflicts.
-
Removing one of the conflicting packages entirely from the project
50% fail
Removing a package may remove required functionality, causing build errors or missing method exceptions.
-
Running 'dotnet restore --force' without resolving the version mismatch
80% fail
Restore only re-downloads packages; it does not resolve version conflicts unless package versions are explicitly aligned.