.Net 6 Azure DevOps Build Fails

I’ve upgraded to latest devops agent and self-hosted sonarqube edition, but I can’t seem to get my .NET 6 project to build.

Hey Daniel.

You’ll need to post some additional details.

  • How have you configured your build? What commands are run?
  • Does your project build when you take SonarQube analysis out of the equation?
  • What errors appear in the logs?

Here is the build YAML

pool:

  name: Azure Pipelines

  demands: java

#Your build pipeline references an undefined variable named ‘Parameters.RestoreBuildProjects’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972

#Your build pipeline references an undefined variable named ‘Parameters.RestoreBuildProjects’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972

#Your build pipeline references the ‘PackageVersion’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971

#Your build pipeline references an undefined variable named ‘Parameters.TestProjects’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972

variables:

  BuildConfiguration: 'Release'

steps:

- task: NuGetToolInstaller@1

  displayName: 'Use NuGet  4.9.1'

  inputs:

    versionSpec: 4.9.1

- powershell: |

   # Set Package Version

   

   $buildNumber = "$(Build.BuildNumber)"

   $packageVersion = $buildNumber.substring($buildNumber.LastIndexOf('_') + 1)

   

   Write-Host "##vso[task.setvariable variable=PackageVersion;]${packageVersion}"

  displayName: 'PowerShell Script'

- task: DotNetCoreCLI@2

  displayName: Restore

  inputs:

    command: restore

    projects: '$(Parameters.RestoreBuildProjects)'

    vstsFeed: '2e228884-1767-4a9d-9a80-7df995b5c9fd'

- task: SonarSource.sonarqube.15B84CA1-B62F-4A2A-A403-89B77A063157.SonarQubePrepare@5

  displayName: 'Prepare analysis on SonarQube'

  inputs:

    SonarQube: SonarQube

    projectKey: Main

    projectName: Main

- task: DotNetCoreCLI@2

  displayName: Build

  inputs:

    projects: '$(Parameters.RestoreBuildProjects)'

    arguments: '--configuration $(BuildConfiguration)'

- task: DotNetCoreCLI@2

  displayName: 'Pack Packages'

  inputs:

    command: custom

    projects: |

     **/*Main.Shared.csproj

     **/*Main.Data.csproj

    custom: pack

    arguments: '-c $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory) /p:VersionPrefix="$(PackageVersion)"'

- task: DotNetCoreCLI@2

  displayName: 'Publish Packages'

  inputs:

    command: push

    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'

    publishVstsFeed: '2e228884-1767-4a9d-9a80-7df995b5c9fd'

- task: DotNetCoreCLI@2

  displayName: Test

  inputs:

    command: test

    projects: '$(Parameters.TestProjects)'

    arguments: '--configuration $(BuildConfiguration)'

- task: SonarSource.sonarqube.6D01813A-9589-4B15-8491-8164AEB38055.SonarQubeAnalyze@5

  displayName: 'Run Code Analysis'

- task: DotNetCoreCLI@2

  displayName: Publish

  inputs:

    command: publish

    publishWebProjects: True

    arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'

    zipAfterPublish: True

- task: PublishBuildArtifacts@1

  displayName: 'Publish Artifact'

  inputs:

    PathtoPublish: '$(build.artifactstagingdirectory)'

    ArtifactName: 'prod-main'

  condition: succeededOrFailed()

The message when the build fails (on the build step) is the following

Time Elapsed 00:01:06.51
##[error]Error: The process 'C:\hostedtoolcache\windows\dotnet\dotnet.exe' failed with exit code 1
##[warning].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[error]Dotnet command failed with non-zero exit code on the following projects : D:\a\1\s\Main\Main.csproj
Finishing: Build


Hey there.

What about the answer to this question?

Yes, it builds when sonarqube is taken out. It will also build if you change it to “standalone scanner” from “msbuild”.

FYI - We have signed up with sonarcloud.io and still have the same issue.

Ok, please close this ticket. Our issue is part of the implecitusing issue with Rosyen. Thanks.