Upgrading SonarQubeCloud tasks from v2 to v4 in ADO changed total LOC analyzed

Hi @AlexJulita,

Thanks for reaching out with your question.

This is a known behaviour change when upgrading to the v4 Azure DevOps tasks. The v4 tasks bundle SonarScanner for .NET v8.0+, which introduced multi-language analysis (sonar.scanner.scanAll) and enabled it by default, see this announcement: SonarScanner for .NET 8, now with other languages auto-detection . That’s the root cause of your LOC growth.

With the old v2 tasks (MSBuild mode), the scanner only counted files explicitly referenced in your .csproj files. With scanAll enabled, it now walks the entire repository and picks up every eligible file — which in a MonoRepo means all .cs files across all solutions, not just the ones being compiled by the solution you’re analysing.

To ‘fix’ this, you can add sonar.scanner.scanAll=false to the extraProperties of each Prepare Analysis Configuration task:

- task: SonarQubePrepare@6
  inputs:
    SonarQube: 'SonarQubeCloud'
    scannerMode: 'dotnet'
    projectKey: 'your-project-key'
    extraProperties: |
      sonar.scanner.scanAll=false

Setting this to false restores the previous behaviour: only files that are part of the build (linked by the .csproj) will be analysed.

If you prefer to keep multi-language analysis on (e.g. for YAML, XML, etc.) but need to exclude other solutions’ directories, you can instead scope each project with sonar.exclusions:

sonar.exclusions=**/OtherSolution/**,**/AnotherSolution/**

Or use sonar.sources to explicitly name the root of the solution being analysed.

For full details, see the Configuring the scanner docs.

Hope that helps!

Best regards,

Stevan