Help running the scanner task for dotnet build

I’ve been trying to make sense of the guidance provided in the documentation here and here. This is Sonar Cloud, however I can’t see what task I use to run the scanner.

  • ALM - Azure DevOps
  • CI - Azure DevOps (Azure Hosted Agent)
  • Scanner command - dotnet sonarscanner
  • Languages - C#

My pipeline looks like below. I’m using the UseDotNet@2 Task to build, restore, etc.

  1. Is that the correct task to install the tool?
  2. What task do I use to run the sonarscanner? Is it ‘task: UseDotNet@2’ with custom?

Assistance much appreciated.

  - job: Build
    - task: UseDotNet@2
      displayName: 'Use .NET Core sdk version'
        version: 6.0.x

    - task: DotnetGlobalToolInstaller@0
      displayName: 'Install latest SonarCloud Scanner'
        name: 'dotnet-sonarscanner'
        checkLatest: true

    - task: DotNetCoreCLI@2
      displayName: Restore
        command: restore
        projects: '**/*.csproj'

    - task: DotNetCoreCLI@2
      displayName: Build
          projects: '**/*.csproj'
          arguments: '--configuration $(BuildConfiguration)'

    - task: DotNetCoreCLI@2
      displayName: Test
        command: test
        projects: '**/test/*/*.csproj'
        arguments: '--configuration $(BuildConfiguration) --filter Category!=Integration --no-build --no-restore'
    - task: DotNetCoreCLI@2
      displayName: 'Publish API'
        command: publish
        projects: '**/*.API.csproj'
        arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'

    - task: PublishBuildArtifacts@1
      displayName: 'Publish Artifact'
        PathtoPublish: '$(build.artifactstagingdirectory)'
        artifactName: 'drop'

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hey there.

I think you’ll find this guide extremely helpful.