C# Dotnet can't analyze - azure devops!

SonarQube Community - latest
Using Azure Devops extension
Able to analyze js.typescript c ode, but C# code says 0 lines of code on sonarqube

I’m running on a self hosted build agent
.NET 8.0
Installed dotnet-sdk-8.0 o
installed dotnet tool install --global dotnet-sonarscanner

My yaml

- task: SonarQubePrepare@7
    inputs:
      SonarQube: 'SonarQube Service Connection'
      scannerMode: 'dotnet'
      projectKey: ''

I then run dotnet build

Then
- task: SonarQubeAnalyze@7

My logs say this in the beginning

SonarScanner for MSBuild 9.0.2
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
Calling the SonarScanner CLI...
.
.
.
INFO: SonarScanner 5.0.1.3006

**It gives me this warning**

WARN: Your project contains C# files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the SonarScanner for .NET 5.x or higher,

I;ve already read the ADO integration docs and
.NET environments | SonarQube Community Build Documentation
and that’s why installed dotnet tool install --global dotnet-sonarscanner on my build agent.

I know the azure sonarqube server extension has the SonarScanner for dotnet built in, so I didn’t even need to install it on the agent.
So it should work…

Should I revert and use the depreciated version of the Azure Devops Sonarqube task
for example ,

SonarQubePrepare@5 instead of SonarQubePrepare@7

cause in version seven, you declare scannerMode: dotnet
in version five, you declare scannerMode: MSBuild

someone was able to fix this issue with version 5, Sensor C# Not Picking Up Some .cs Files - SonarQube Server / Community Build - Sonar Community

So… is this a bug with azure sonarqube devops extension?

Please help asap

Hey there.

Can you please share your full Azure DevOps Pipeline YML?

It would also help to see the entire logs from the pipeline.

@Colin

//
- task: SonarQubePrepare@7
inputs:
SonarQube: ‘SonarQube Service Connection’
scannerMode: ‘dotnet’
projectKey: ‘…’

  - task: DotNetCoreCLI@2
    inputs:
      command: 'build'
      projects: "$(Build.SourcesDirectory)/...../*.csproj"

  - task: SonarQubeAnalyze@7

//
logs
for
SonarQube analyze @7 task

(blurred out for security purposes):
INFO: Indexing files…
INFO: Indexing files of module ‘’
INFO: Base dir: /…/_work/1/s/…/FOLDER
INFO: Source paths: xxx.cs, xxx/yy…

INFO: X files indexed

INFO: ------------- Run sensors on module X
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=72ms
INFO: Sensor C# Project Type Information [csharp]
INFO: Sensor C# Project Type Information [csharp] (done) | time=1ms
INFO: Sensor C# Analysis Log [csharp]
INFO: Sensor C# Analysis Log [csharp] (done) | time=26ms
INFO: Sensor C# Telemetry [csharp]
INFO: Sensor C# Telemetry [csharp] (done) | time=4ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=0ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=3ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: ‘sonar.coverage.jacoco.xmlReportPaths’ is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=2ms
INFO: Sensor Java Config Sensor [iac]
.
.
.
.
Logs then show it is able to analyze typescript etc code…

then

INFO: ------------- Run sensors on project X
INFO: Sensor C# Telemetry processor [csharp]
INFO: Sensor C# Telemetry processor [csharp] (done) | time=3ms
INFO: Sensor C# [csharp]
WARN: Your project contains C# files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the SonarScanner for .NET 5.x or higher, see https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html
INFO: Sensor C# [csharp] (done) | time=2ms
INFO: Sensor Analysis Warnings import [csharp]
INFO: Sensor Analysis Warnings import [csharp] (done) | time=13ms
INFO: Sensor C# File Caching Sensor [csharp]
INFO: Sensor C# File Caching Sensor [csharp] (done) | time=17ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=37ms

This is neither your full pipeline, or the complete logs from your build. I’m sorry, there’s not enough information in what you’ve shared to be helpful.

@Colin
There’s nothing else related to this in my pipeline. This is the step where the .NET code is being built in the pipeline.

The logs I shared show what happens during the task that analyzes after the dotnet build
It successfully performs analysis on TypeScript and JavaScript code.

I cant share the whole logs for security purposes
@Colin

@Colin
Seems like my sonar scanner is version SonarScanner 5.0.1.3006 even though I’m using the latest Azure DevOps SonarQube version, so there’s a bug for SonarQube extension as you agreed to @Colin

So I specified the latest version in my prepare

  - task: SonarQubePrepare@7
    inputs:
      SonarQube: 'SonarQube Connection'
      scannerMode: 'dotnet'
      projectKey: ''
      projectName: ''
      msBuildVersion: '9.0.2.104486'

In the SonarQubeprepare logs it says

**Found tool in cache: SonarScanner .NET 9.0.2 x64**

/usr/bin/dotnet /azp/_work/_tool/SonarScanner .NET/9.0.2/x64/SonarScanner.MSBuild.dll begin /k:al;smdl;asdm

SonarScanner for MSBuild 9.0.2

Using the .NET Core version of the Scanner for MSBuild

However in SOnarQubeAnalys log it still says the version is this:

SonarScanner for MSBuild 9.0.2

Using the .NET Core version of the Scanner for MSBuild

Post-processing started.

Calling the SonarScanner CLI...

INFO: Scanner configuration file: /azp/_work/_tool/SonarScanner .NET/9.0.2/x64/sonar-scanner-5.0.1.3006/conf/sonar-scanner.properties

INFO: Project root configuration file: /azp/_work/1/.sonarqube/out/sonar-project.properties

**INFO: SonarScanner 5.0.1.3006**

INFO: Java 17.0.11 Eclipse Adoptium (64-bit)

INFO: Linux 5.15.164.1-1.cm2 amd64

INFO: User cache: /home/agent/.sonar/

From

Sonar employee says you cant specify the scanner version in the prepare task…
But documentation says you can via msBuildVersion paramtee

I’ve tried SonarQubexxx@7 and SonarQubexxx@5 and both don’t get the most up to date sonarscanner version

Hi there, @sonarhelp

The first line of your log indicates you are indeed using version 9.0.2 of the SonarScanner for .NET:

SonarScanner for MSBuild 9.0.2

The line you are referring to is an indication of the version of the embedded Scanner CLI (this is a technical detail of the implementation), which is v5.0 at this time.

As for why your get this error, @Colin is right. Without more details on your pipeline (prepare, build and analyze tasks at least) and your logs (again, prepare, build, and analyze tasks), it will be difficult to help more. You can send the logs (please generate them by setting sonar.verbose to true in your Prepare task’s extraProperties input) by direct message to us if you do not want to post them publicly (which is understandable).

Denis

So the sonar scanner version is 5 on purpose even though the latest is 9.x.x??

My logs say the version 5 isnt enough for the c# files

I can send logs privately

@sonarhelp as I said, this is the version of an internal component, logged for purposes of diagnostics, nothing more. The actual scanner version is printed at the start, and is indeed 9.x.
Please do send the logs via private message so we can help, as well as your pipeline.

Denis