Unable to build the ASP.Net Core 7 in azure devops pipeline (CI), Using Classic pipeline and ASP.net core template
Error message :
##[error]C:Program Filesdotnetsdk6.0.203SdksMicrosoft.NET.SdktargetsMicrosoft.NET.TargetFrameworkInference.targets(144,5)
: Error NETSDK1045: The current .NET SDK does not support targeting .NET 7.0.
Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 7.0.
2
Answers
Add a task to install the .NET version that you need (you can change 7.x to something more specific)
Docs
We faced this same issue in upgrading to .NET 7 on our self hosted agents, and despite adding the
UseDotNet@2
as described by silent, we still ended up with failures referencing various 6.0.x SDK targets.The issue ended up being resolved through this answer. It was due to a previous install of .NET 6 and the variable
MSBuildSDKsPath
. If you have self hosted agents, check the "Capabilities" of the agent to show the variable itself.Failing that, check the value of that through the pipeline itself with a step like;
An example snippet of our ci-pipeline.yaml that worked is as follows. Important notes are MSBuildSDKsPath overriding whatever environment variable is set on the agent to reflect the location of the newly installed .NET 7 SDK;