Search code examples
azure-devopsazure-pipelinespipelineazure-pipelines-yaml

Pipeline not work after updating to .net 6


I have updated my website to .net 6. It also works locally. However, my yaml pipeline in Azure DevOps is no longer running. There is an error in the publishing step for all .csproj files in solution like this. I don't know, how I can configure that it should use .net 6.

C:\Program Files\dotnet\sdk\5.0.403\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(141,5): 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. [D:\a\1\s\04_Contracts\Contracts\Contracts.csproj]
##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1

Here is the Pipeline step for publishing.

- task: DotNetCoreCLI@2
  displayName: 'dotnet publish'
  inputs:
    command: publish
    publishWebProjects: false
    projects: '**/*.csproj'
    arguments: '-r linux-x64 --output $(build.artifactstagingdirectory)'

Solution

  • You need first to install .NET 6 SDK in the agent, add it before the DotNetCoreCLI:

    - task: UseDotNet@2
      displayName: 'Install .NET Core sdk 6.x'
      inputs:
        version: 6.x