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

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

Cache stampede: when our cache turned against us

While investigating some performance issues, we ran into an ASP.NET Core API that cached a fairly expensive aggregation query for 60 seconds. Under normal load, that was fine: one request rebuilds the cache, everyone else reads from it. Under peak load, dozens of requests would arrive in that same expiry window, all see a cache miss, and all fire the same expensive query in parallel. The database didn't like that. That was the moment when our caching layer stopped helping and started hurting. A burst of requests comes in at the same time, all miss the cache, and all go hammer the database or the downstream API at once. That's a cache stampede . The cache was supposed to protect our backend, and for a few hundred milliseconds it did the opposite. Why this happens IMemoryCache.GetOrCreate (and its async sibling) looks like it protects you, but it doesn't add any locking on its own. Look at the naive version: public async Task<Report> GetReportAsync(string key) ...

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.