While working with Azure DevOps pipelines I encountered a frustrating NuGet package restore failure. The culprit behind these issues is Azure DevOps using an outdated version of NuGet by default, which lead to version conflicts and compatibility problems with modern .NET projects.
The problem: Old NuGet versions cause conflicts
When running NuGet restore tasks in Azure DevOps, you might encounter errors like these:
##[error]The nuget command failed with exit code(1) and error(NU1107: Version conflict detected for Castle.Core. Install/reference Castle.Core 3.1.0 directly to project SOFACore.PerformanceBenchmarks to resolve this issue.
SOFACore.PerformanceBenchmarks -> Castle.Core.AsyncInterceptor 0.1.0 -> Castle.Core (>= 3.1.0)
SOFACore.PerformanceBenchmarks -> SOFACore.NHibernate -> NHibernate 2.1.2.4000 -> Castle.DynamicProxy 2.1.0 -> Castle.Core (= 1.1.0).
NU1107: Version conflict detected for xunit.v3.extensibility.core. Install/reference xunit.v3.extensibility.core 2.0.0 directly to project SOFACore.NHibernate.Tests to resolve this issue.
SOFACore.NHibernate.Tests -> Serilog.Sinks.XUnit.v3 1.0.0 -> xunit.v3.extensibility.core (>= 2.0.0)
SOFACore.NHibernate.Tests -> xunit.v3 1.0.0 -> xunit.v3.core 1.0.0 -> xunit.v3.extensibility.core (= 1.0.0).
NU1202: Package Microsoft.AspNetCore.Authentication.Negotiate 3.0.0 is not compatible with net90 (.NETFramework,Version=v9.0). Package Microsoft.AspNetCore.Authentication.Negotiate 3.0.0 supports: netcoreapp3.0 (.NETCoreApp,Version=v3.0)
NU1202: Package Microsoft.AspNetCore.Authentication.Negotiate 3.0.0 is not compatible with net90 (.NETFramework,Version=v9.0). Package Microsoft.AspNetCore.Authentication.Negotiate 3.0.0 supports: netcoreapp3.0 (.NETCoreApp,Version=v3.0)
NU1107: Version conflict detected for xunit.v3.extensibility.core. Install/reference xunit.v3.extensibility.core 2.0.0 directly to project SOFACore.QueryService.Tests to resolve this issue.
These errors typically indicate:
- NU1107: Version conflicts between different packages requiring different versions of the same dependency
- NU1202: Framework compatibility issues where packages don't support the target framework
However I was convinced that this could not be the root cause of the problem as I knew that I had specified the correct versions in my Directory.Packages.props
file (I’m using Central Package Management in this project).
Root Cause: Azure DevOps default NuGet version
I took a more detailed look at the build log and noticed the following:
Caching tool: NuGet 4.9.6 x64
Found tool in cache: NuGet 4.9.6 x64
Resolved from tool cache: 4.9.6
Using version: 4.9.6
Found tool in cache: NuGet 4.9.6 x64
C:\Windows\system32\chcp.com 65001
Active code page: 65001
Detected NuGet version 4.9.6.8 / 4.9.6+a32bce39889f724fbd11cfd12e946f802168b583
The issue stems from Azure DevOps using NuGet version 4.9.6 by default in many pipeline configurations. While this version was adequate for older .NET projects, it struggles with Central Package Management.
The NuGet restore task seems to use this (old) version by default:
The Solution: Explicitly install a modern NuGet version
The fix is straightforward: explicitly install a newer version of NuGet before running your restore task.
Step 1: Add NuGetToolInstaller task
Add this task before your NuGet restore task in your Azure DevOps pipeline:
Step 2: Keep your existing Restore task
The existing NuGet restore task remains unchanged:
Conclusion
Don't let outdated tooling derail your CI/CD pipeline. By explicitly installing a modern NuGet version in your Azure DevOps pipeline, you can resolve most package restore conflicts and ensure compatibility with modern .NET projects. This simple one-line addition can save hours of debugging and frustration.
The next time you see those dreaded NU1107 or NU1202 errors, remember: the solution might be as simple as updating your NuGet version.