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.


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

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

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

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

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

    - task: PublishBuildArtifacts@1
      displayName: 'Publish Artifact'
      inputs:
        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.