1
votes

We have upgraded all projects to .Net core 2.2 from .net core 2.1 and before upgrade all projects were building successfully on azure devops pipeline but after upgrade to .net core 2.2, Nuget restore task failing with below error

018-12-17T22:20:06.8107786Z ##[error]The nuget command failed with exit code(1) and error(C:\Program Files\dotnet\sdk\2.1.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 2.2. Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 2.2.

enter image description here

enter image description here

I have updated .net core 2.2 references to all projects and we are not using nuget.exe from project.

What am I missing ?

Update 1

As per rick's reply, I added .net core task in pipeline but still failing

enter image description here

3

3 Answers

1
votes

Try running dotnet restore instead of using the nuget task.

You can find more documentation over here: Build, test, and deploy .NET Core apps in Azure Pipelines - Restore dependencies

NuGet is a popular way to depend on code that you don't build. You can download NuGet packages by running the dotnet restore command either through the .NET Core task or directly in a script in your pipeline.

Edit:
Have a look at the NuGet packages you're using, since the message you're getting tries to tell you something:
The current .NET SDK does not support targeting .NET Core 2.2. Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 2.2
Are all of your projects targetting the same version?

1
votes

After trying out different solutions, I came across scott hanselman's blog which talks about Azure Devops CI on asp.net core 2.2 preview but Blog talks about same error and same issue is solved by adding .NET Core SDK Installer task.

https://www.hanselman.com/blog/AzureDevOpsContinuousBuildDeployTestWithASPNETCore22PreviewInOneHour.aspx

My issue got fixed by adding .NET Core SDK Installer task with 2.2.10 version.

1
votes

I ran into a similar issue using classic pipelines. I was updating a web app to .NET Core 3.1 when I ran into the following error on the .NET Restore step.

[error]The nuget command failed with exit code(1) and error(C:\Program Files\dotnet\sdk\2.2.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.1. Either target .NET Core 2.2 or lower, or use a version of the .NET SDK that supports .NET Core 3.1.

I was able to get around this by changing my agent pool to something newer (2019) as shown below than what was there (2017) to begin with which couldn't handle the newer SDK.

Picture of Phase 1 classic view Agent Pool = Azure Pipelines and Agent Specification = windows-2019