Reputation: 43
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 Files\dotnet\sdk\6.0.203\Sdks\Microsoft.NET.Sdk\targets\Microsoft.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.
Upvotes: 2
Views: 2579
Reputation: 6344
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;
- script: set
displayName: show all env vars
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;
trigger:
branches:
include:
- '*'
exclude:
- develop
- main
variables:
- name: solution
value: '**/*.sln'
- name: BuildConfiguration
value: 'Release'
- name: MSBuildSDKsPath
value: C:\agent\_work\_tool\dotnet\sdk\7.0.102\Sdks
jobs:
- job: Build
pool:
vmImage: 'windows-latest'
name: 'Modern'
workspace:
clean: all
steps:
- script: set
displayName: show all env vars
- checkout: self
persistCredentials: true
- task: UseDotNet@2
displayName: 'Use .NET 7.x'
inputs:
packageType: 'sdk'
version: 7.x
performMultiLevelLookup: true
includePreviewVersions: false
installationPath: $(Agent.ToolsDirectory)/dotnet
Upvotes: 1