C# Files not being analyzed

csharp

(Joaquim Ferreira) #1

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


(Nicolas Bontoux) #2

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.


(Joaquim Ferreira) #3

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.


(Joaquim Ferreira) #4

A picture from SonarQube


(Joaquim Ferreira) #5

A picture from SonnarScanner for ms Build


(Amaury Levé) #6

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


(Joaquim Ferreira) #7

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)


(Amaury Levé) #8

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.


(Joaquim Ferreira) #9

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


(Amaury Levé) #10

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.


(Joaquim Ferreira) #11

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


(Joaquim Ferreira) #12

Hello I realized what I was doing wrong.

Apologies last time i used SonarQube was less that 7.

Its now working.

Apologies for this


(Leonardo) #13

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


(Hilal Emeksiz) #14

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


(Amaury Levé) #15

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.