Error NETSDK1045: The current .NET SDK does not support targeting .NET 6.0
Sebastian Wright
I spent 2 hours trying to figure out what's wrong with my pipeline for Azure Functions .NET6 (on Windows).
Error NETSDK1045: The current .NET SDK does not support targeting .NET 6.0. Either target .NET 5.0 or lower, or use a version of the .NET SDK that supports .NET 6.0. 7 Answers
I found the solution here
It works if I specify the .NET Core SDK version & set preview version to true
- task: UseDotNet@2 displayName: 'Use .NET Core sdk' inputs: packageType: 'sdk' version: '6.0.x' includePreviewVersions: trueSo my final pipelines looks something like this
# .NET Core Function App to Windows on Azure
# Build a .NET Core function app and deploy it to Azure as a Windows function App.
# Add steps that analyze code, save build artifacts, deploy, and more:
#
trigger:
- master
- main
- dev
variables: azureSubscription: 'XXXX' functionAppName: 'XXXX' vmImageName: 'windows-latest' workingDirectory: '$(System.DefaultWorkingDirectory)/XXXX'
stages:
- stage: Build displayName: Build stage jobs: - job: Build displayName: Build pool: vmImage: $(vmImageName) steps: - task: UseDotNet@2 displayName: 'Use .NET 6 Core sdk' inputs: packageType: 'sdk' version: '6.0.x' includePreviewVersions: true - task: DotNetCoreCLI@2 displayName: Build inputs: command: 'build' projects: | $(workingDirectory)/*.csproj arguments: --output $(System.DefaultWorkingDirectory)/publish_output --configuration Release - task: ArchiveFiles@2 displayName: 'Archive files' inputs: rootFolderOrFile: '$(System.DefaultWorkingDirectory)/publish_output' includeRootFolder: false archiveType: zip archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip replaceExistingArchive: true - publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip artifact: drop
- stage: Deploy displayName: Deploy stage dependsOn: Build condition: succeeded() jobs: - deployment: Deploy displayName: Deploy environment: 'development' pool: vmImage: $(vmImageName) strategy: runOnce: deploy: steps: - task: AzureFunctionApp@1 displayName: 'Azure functions app deploy' inputs: azureSubscription: '$(azureSubscription)' appType: functionApp appName: $(functionAppName) package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip' 5 I had this error when running a project, and installing the .Net 6.0 SDK solved my issue.
For the classic editor - just set the agent to Windows 2022 and make sure to use the latest Nuget Version (I used 5.8 and it worked fine).
1I got this error when I was running pipeline on .Net6 core project made on VS2022. After changing pool vmimage to windows-2022 from windows-latest, things worked for me.
Also added latest version for NugetinstalleNuget versions
steps: - task: NuGetToolInstaller@1 inputs: versionSpec: '6.1' checkLatest: trueNow my pipeline looks like this,
trigger:
- master
pool: vmImage: 'windows-2022'
variables: solution: '**/*.sln' buildPlatform: 'Any CPU' buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1 inputs: versionSpec: '6.1' checkLatest: true
- task: NuGetCommand@2 inputs: restoreSolution: '$(solution)'
- task: VSBuild@1 inputs: solution: '$(solution)' msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)' A colleague of mine build an console-app towards .net 6.0 in VS 2022.
I opened the solution in VS 2019 and got this exact error.
It worked like a charm when I also used VS 2022..
Resolved : with .Net6 core project made on VS2022.Need to use a version of the .NET SDK that supports .NET 6.0.
before .NET Core publish task need to add another Task (below one for use specific version of SDK 6.0)
steps:
- task: UseDotNet@2 displayName: 'Use .NET Core sdk 6.0.x' inputs: packageType: '$(Parameters.packageType)' version: 6.0.x includePreviewVersions: trueMy complete YAML looks like ( build successfully 26 may, 2022)
variables:
- name: BuildParameters.packageType value: sdk
resources: repositories: - repository: self type: git ref: refs/heads/Develop
jobs:
- job: Job_1 displayName: Agent job 1 pool: vmImage: windows-2019 steps: - checkout: self - task: NuGetToolInstaller@1 displayName: 'Use NuGet ' - task: NuGetCommand@2 displayName: NuGet restore inputs: solution: Marielinas - task: UseDotNet@2 displayName: Use .NET Core sdk 6.0.x inputs: packageType: $(BuildParameters.packageType) version: 6.0.x includePreviewVersions: true - task: DotNetCoreCLI@2 displayName: dotnet publish inputs: command: publish arguments: -c release --output $(Build.ArtifactStagingDirectory) workingDirectory: Marielinas.ASP.NET6.0 - task: AzureWebApp@1 displayName: 'Azure Web App Deploy: marielinasshop' inputs: azureSubscription: 37f84ce6-e4f1-4a03-b107-9c9a527dff4a appType: webApp appName: marielinasshop deployToSlotOrASE: true resourceGroupName: GreenLab package: $(Build.ArtifactStagingDirectory)/**/*.zip
... Update Visual Studio to Vs2019 16.11.7 My Problem solved.
1