Sonarqube does not analyze .cs files

Hi everyone!

I’ll try to explain my problem as clear as possible.

#My setup

I’m working with Jenkins and Sonarqube as containers of a pod (Podman) on CentOS Stream 8.

I also have a Windows Server 2019 working as a node of Jenkins, where I deploy my C# project.

#What I am trying to achieve

I’ve configured a job in Jenkins which:

  • Downloads the C# project from Git to the node
  • Analyzes with Sonarqube the static code it just downloaded

#The output I get once the job finishes

The Build in Jenkins succeeds, but the console output says:

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 SonarScanner for .NET | SonarQube Docs
INFO: Sensor C# [csharp] (done) | time=1ms

On sonarqube (http://my-ip-address:9000/code?=mycsproject), I get all files analyzed (.html, .aspx, …) except the .cs ones.

#What I have tried so far

I’ve configured the Jenkins pipeline like this:

I’m not really sure if I’m doing something wrong. I hope someone can help me…
Thank you!!!

Hi Koldo,

welcome to the community!

I’m relatively new here, but I’m using sonarscanner locally for C# projects and have not yet had this issue. My C# projects target the .Net 5 and .Net 6 frameworks. Which frameworks do you target?

If your projects do not target .Net 5 or higher, then it might be time to upgrade your target frameworks, as LTS is ending for 3.1 at the end of this year.

Otherwise, can you check your version of sonarscanner and confirm that it has support for .Net 5.x or higher? You can check that in the listed version here under the header “SonarScanner for .NET”. If it doesn’t, then you might have to reinstall sonarscanner to a version that does support .Net 5.x or higher

Tip: Running the dotnet tool install command without a version will install the most recent version.

dotnet tool install --global dotnet-sonarscanner 

To add onto @cwata’s answer – it looks like you are using the Jenkins steps that directly use the SonarScanner CLI. It is also possible to select steps that use the Scanner for MSBuild / .NET, which is required for the analysis of C# code.

These two steps should sandwich the step where you actually build your C# project. You can find more details in the docs @cwata previously mentioned.

Hi @Colin and @cwata, thank you guys for replying!

The framework I’m targetting is .Net 4.7.
My Jenkins installs from Maven Central the SonarQube Scanner version


I don’t really know if this version is compatible with .Net 4.7. If not I can try installing a later version from command.

Anyways, according to what @Colin proposes, is it mandatory to build the project? I mean, is it possible to scan the static code (as plain text code) as I do in other projects such as python, java, … without building it?

Thanks again guys!

A few languages (Java, C#, C/C++/Objective-C) are considered compiled languages and require a build for analysis to take place. There are some workarounds with Java (which result in worse analysis results) – there is no workaround for .NET.

Oh okay, I see. Then I’ll try the way you proposed, thanks a lot @Colin :wink: :wink: