错误 NETSDK1045:当前 .NET SDK 不支持定位 .NET 6.0

joh*_*kes 61 azure-devops .net-6.0

我花了 2 个小时试图找出 Azure Functions .NET6(在 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.
Run Code Online (Sandbox Code Playgroud)

joh*_*kes 57

我在这里找到了解决方案https://jaliyaaudgedara.blogspot.com/2021/07/azure-devops-building-projects.html
如果我指定 .NET Core SDK 版本并将预览版本设置为 true,它就可以工作

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk'
  inputs:
    packageType: 'sdk'
    version: '6.0.x'
    includePreviewVersions: true
Run Code Online (Sandbox Code Playgroud)

所以我的最终管道看起来像这样

# .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'
Run Code Online (Sandbox Code Playgroud)

  • 版本号可以在此文档中找到:https://github.com/dotnet/core/blob/main/release-notes/releases-index.json(例如 6.0.100) (3认同)
  • .NET 新版本的发布与默认支持该版本的代理之间通常存在延迟。在撰写本文时,为此提出了一个未解决的问题:https://github.com/dotnet/core/issues/6907 (3认同)
  • 我能够成功地利用这个解决方案,但没有使用“includePreviewVersions: true”。 (2认同)

小智 16

对于经典编辑器 - 只需将代理设置为 Windows 2022 并确保使用最新的 Nuget 版本(我使用的是 5.8,它工作正常)。


小智 11

我在运行项目时遇到此错误,安装 .Net 6.0 SDK 解决了我的问题。https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/sdk-6.0.102-windows-x64-installer