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.

Podman– Command execution failed with exit code 125

After updating WSL on one of the developer machines, Podman failed to work. When we took a look through Podman Desktop, we noticed that Podman had stopped running and returned the following error message: Error: Command execution failed with exit code 125 Here are the steps we tried to fix the issue: We started by running podman info to get some extra details on what could be wrong: >podman info OS: windows/amd64 provider: wsl version: 5.3.1 Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM Error: unable to connect to Podman socket: failed to connect: dial tcp 127.0.0.1:2655: connectex: No connection could be made because the target machine actively refused it. That makes sense as the podman VM was not running. Let’s check the VM: >podman machine list NAME         ...