59

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.
johnykes
  • 1,663
  • 2
  • 9
  • 25

8 Answers8

55

I found the solution here https://jaliyaudagedara.blogspot.com/2021/07/azure-devops-building-projects.html
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: true

So 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:
# https://learn.microsoft.com/en-us/azure/devops/pipelines/languages/dotnet-core

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'
johnykes
  • 1,663
  • 2
  • 9
  • 25
  • 3
    The version numbers can be found in this document: https://github.com/dotnet/core/blob/main/release-notes/releases-index.json (for example 6.0.100) – Nick Nov 23 '21 at 17:01
  • 3
    It seems there's usually a delay between a new version of .NET being released, and these agents supporting that version by default. At the time of writing, there's an open issue raised for this: https://github.com/dotnet/core/issues/6907 – Jamie Burns Nov 26 '21 at 09:27
  • 1
    any idea how that works using classic editor? – yBother Nov 29 '21 at 16:07
  • I guess it is Use .NET Core sdk – yBother Nov 29 '21 at 16:36
  • 2
    I was able to leverage this solution successfully, but did so without `includePreviewVersions: true`. – Adam Schumph Jun 06 '22 at 00:47
  • Updated the Agent-Specification to windows-2022 and Use .Net Core version to 6 worked for me – Abhi Aug 18 '22 at 10:59
14

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

Steve G
  • 151
  • 1
  • 3
11

I had this error when running a project, and installing the .Net 6.0 SDK solved my issue. https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/sdk-6.0.102-windows-x64-installer

user14181068
  • 269
  • 3
  • 7
4

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

Andreas
  • 775
  • 2
  • 11
  • 20
3

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

Reference MS Documentation

Also added latest version for Nugetinstalle Nuget versions

steps:
 - task: NuGetToolInstaller@1
 inputs:
   versionSpec: '6.1'
   checkLatest: true

Now 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)'
Kumar Sambhav Pandey
  • 1,713
  • 4
  • 22
  • 33
2

Update Visual Studio to Vs2019 16.11.7 My Problem solved.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 16 '22 at 06:49
  • Due to Microsoft breaking changes, an upgrade to Visual Studio can fix this issue; Is what he was referring to I believe: https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/6.0/vs-msbuild-version – sean2078 Jun 27 '22 at 14:04
  • 1
    Question clearly states it's about Azure – Andreas Pardeike Jul 01 '22 at 07:35
  • Updating also solved it with VS 2022. – RoJaIt May 19 '23 at 13:31
1

I got the error below in latest Visual Studio 2022 17.6 even though I had SDK 8.0.100-preview.4 installed:

NETSDK1045 The current .NET SDK does not support targeting .NET 8.0. Either target .NET 7.0 or lower, or use a version of the .NET SDK that supports .NET 8.0

Looking at release notes they however stated that:

This release is only compatible with Visual Studio 2022 (v17.7 Preview 1).

https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/sdk-8.0.100-preview.4-windows-x64-installer

Downloaded preview and then it worked.

https://visualstudio.microsoft.com/vs/preview/#download-preview

Ogglas
  • 62,132
  • 37
  • 328
  • 418
  • In my case, I had installed VS version 17.7.0 Preview 1.0 along with .NET 8. But after running "dotnet --list-sdks" I could tell that I didn't have any .NET 8 versions installed. Either it's a VS Installer bug or it doesn't install preview versions. So, I had to manually install .NET 8 as you suggested. – Tangere Apps May 24 '23 at 23:44
0

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: true

My 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
...
Ahmed Zamil
  • 238
  • 2
  • 6
  • 17