C# Files not being analyzed

Hi there I got a new pipeline using Jenkins and SonarQube. I have used the product in the pass, and i got it working.

My problem is for some reason my C# code is not being analyzed at all.

all my .JS and XML are being analyzed.

Can some one please advise.

Kind Regards

Joaquim

Hi Joaquim,

Welcome on this forum, please read the welcome post for an insight on best-practices and must-share information. Notably:

In this case here I would advise you first review recommendations on how to analyse C# code (and also the Jenkins integration of Scanner for MSBuild). Give it a try, iterate a bit, and if not successful then do share more details about what you’ve tried and what your findings/observations are so far.

Hi there I followed all the documentation I could find and tried a whole variety of things and not much luck.

Some pics of my settings in Jenkins.

A picture from SonarQube

A picture from SonnarScanner for ms Build

Hi @jjferreira,

  1. Could you let us know the version of:

    • SonarQube
    • SonarC#
    • the scanner of jenkins
  2. Could you provide the full log (i.e. with /d:sonar.verbose=true on the begin)?

  3. Can you see the C# files in the project dashboard?

  4. Can you see any metric for those files?

  5. Looking at the log of the build, can you see some warning SXXX?

Cheers,
Amaury

Hi there, here are the following versions of the products im using.

  • SonarQube: 7.3
  • SonarC#: (build 5690)**
  • the scanner of jenkins

I was not sure where to get the file generated by the verbose so i uploaded the file generated by jenkins.

Also I notice indeed there is quite a few warnings.

CSC : warning CS8032: An instance of analyzer SonarAnalyzer.Rules.CSharp.LiteralsShouldNotBePassedAsLocalizedParameters cannot be created from C:\Users\jferreira\AppData\Local\Temp.sonarqube\resources\0\SonarAnalyzer.CSharp.dll : Could not load file or assembly ‘Microsoft.CodeAnalysis, Version=1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified…

SonnarReport.txt (2.4 MB)

As you may have noticed in the release notes SonarC# 7.0 upwards requires Roslyn 1.3 which means that you need to build using Visual Studio 2015 Update 3 / Build Tools 2015 Update 3.

The warning CS8032 you are quoting actually warns you that you don’t have the required version of Roslyn (i.e. Visual Studio / Build Tools) installed on your machine.

Please update.

Can I confirm do I really need to be using .NET 4.6.

At the moment if i change to .net 4.6 I got all sorts of errors, something that I need to address at some point, but was not planning to do it now.

Back in January I used an earlier version and everything was so much easier.

Is there away to get around this .NET 4.6? or I’m forced to update my app to 4.6

I didn’t said you have to update to .Net 4.6 but simply that you have to update the version of MSBuild / Visual Studio you are using.

My understanding was that I needed to add the following packadges


Microsoft.CodeAnalysis" version=“1.3.1”
Microsoft.CodeAnalysis.Analyzers" version=“1.1.0”
Microsoft.CodeAnalysis.Common" version=“1.3.1”
Microsoft.CodeAnalysis.CSharp" version=“1.3.1”
Microsoft.CodeAnalysis.CSharp.Workspaces" version=“1.3.1”
Microsoft.CodeAnalysis.VisualBasic" version=“1.3.1”
Microsoft.CodeAnalysis.VisualBasic.Workspaces" version=“1.3.1”
Microsoft.CodeAnalysis.Workspaces.Common" version=“1.3.1”

In doing that I have the need to update to .NET 4.6, apologies if i miss interpreting.

Kind regads

Hello I realized what I was doing wrong.

Apologies last time i used SonarQube was less that 7.

Its now working.

Apologies for this

would you mind telling me what were you doing wrong? i’m having the same problem

Hello @Ammo
you said:
“I didn’t said you have to update to .Net 4.6 but simply that you have to update the version of MSBuild / Visual Studio you are using.”

In the second command below do we have to give 4.6 as target framework? Our server version is community 7.0 and c# plugin version is 5.8 (build 645.
In addition what is the lowest framework version Sonar supports in c# analysis?

1)SonarScanner.MSBuild.exe begin /k: "project-key"
2)MSBuild.exe /t:Rebuild
3)SonarScanner.MSBuild.exe end

Thank You

Hi @Leonardo-Ferreira,

If you are still experiencing some issue, could you please create a new thread explaining the problem you are facing (even if it seems similar to this one) so that we can help you?

Hi @Hilal_Emeksiz,

Looking at the update center for SQ 7.0 I can see that the version 5.8 of SonarC# is not officially supported so you will have to update it. To answer the second part of your question, we need the .net 4.6 for the scanner for msbuild to run BUT we don’t have any requirement on which version your project is targeting.

Hello all,I have the same problem, C# files not being analyzed, but I think the cause is different from what has been discussed in this post.

I’m using SonarQube 7.5 and using visual studio 2017 to build. For some reason most of the projects in my solution are detected from SonarQube as test projects. I don’t understand why, because the path does not include the Test word.

After the analysis was performed, when watching the file ProjectInfo.log, I can see most of my projects are flaged as test projects when they aren’t.

I upload the ProjectInfo.log file for reference. I cannot see where the analysis log is generated when using the sonar.verbose parameter. Please tell me if needed.

ProjectInfo.log.txt (2.2 KB)

I fix this issue by upgrading the package Microsoft.Net.Compilers from version 1.0 to version 1.3.2

1 Like