Skip to main content

Azure DevOps Pipelines: Fixing the old NuGet version problem

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.

More information

NuGetCommand defaulting to very old version of NuGet on windows-2022 · Issue #16088 · microsoft/azure-pipelines-tasks

NuGet Central Package Management

Popular posts from this blog

Kubernetes–Limit your environmental impact

Reducing the carbon footprint and CO2 emission of our (cloud) workloads, is a responsibility of all of us. If you are running a Kubernetes cluster, have a look at Kube-Green . kube-green is a simple Kubernetes operator that automatically shuts down (some of) your pods when you don't need them. A single pod produces about 11 Kg CO2eq per year( here the calculation). Reason enough to give it a try! Installing kube-green in your cluster The easiest way to install the operator in your cluster is through kubectl. We first need to install a cert-manager: kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.5/cert-manager.yaml Remark: Wait a minute before you continue as it can take some time before the cert-manager is up & running inside your cluster. Now we can install the kube-green operator: kubectl apply -f https://github.com/kube-green/kube-green/releases/latest/download/kube-green.yaml Now in the namespace where we want t...

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.

DevToys–A swiss army knife for developers

As a developer there are a lot of small tasks you need to do as part of your coding, debugging and testing activities.  DevToys is an offline windows app that tries to help you with these tasks. Instead of using different websites you get a fully offline experience offering help for a large list of tasks. Many tools are available. Here is the current list: Converters JSON <> YAML Timestamp Number Base Cron Parser Encoders / Decoders HTML URL Base64 Text & Image GZip JWT Decoder Formatters JSON SQL XML Generators Hash (MD5, SHA1, SHA256, SHA512) UUID 1 and 4 Lorem Ipsum Checksum Text Escape / Unescape Inspector & Case Converter Regex Tester Text Comparer XML Validator Markdown Preview Graphic Col...