1
votes

I prepared Sonar for analizing my C# project. I installed sonar and sonar-runner and also configured the C# plugins (.NET Core, C# Core, FxCop, Gendarme, Gallio, OpenCover and StyleCop)

So far everythings works fine. In Sonar I see my code statistics (LOCs and so on) and I also see the code violations. There is no code coverage buts thats ok because I do not have any tests.

The problem is that I only see violations regarding Stylecop, so it just shows some code style problems. But I am sure that my application also must have other violations that should be detected by FxCop and the other plugins.

In this picture one can just see that it shows a violation from StyleCop. All my violations are ONLY from StyleCop.

enter image description here

In the Sonar C# Documentation I have read that it can happen that Analysis succeeds but too few violations were found, maybe because of the wrong assambly direction. I show you my sonar-runner.properties, maybe here is the cause of my problems:

#----- Default Sonar server
#sonar.host.url=http://localhost:9000

#----- PostgreSQL
#sonar.jdbc.url=jdbc:postgresql://localhost/sonar
#sonar.jdbc.driver=org.postgresql.Driver

#----- MySQL
#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
#sonar.jdbc.driver=com.mysql.jdbc.Driver

#----- Oracle
#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE
#sonar.jdbc.driver=oracle.jdbc.driver.OracleDriver

#----- Global database settings
#sonar.jdbc.username=sonar
#sonar.jdbc.password=sonar

#----- Default directory layout
sonar.sources=src
sonar.tests=src
sonar.binaries=src

#----- Default source code encoding
#sonar.sourceEncoding=UTF-8

I also want to list my application structure:

-->ProjectMainFolder
   -->Project.sln
   -->sonar-project.properties

   -->Project1Folder
       -->bin
       -->object
       -->Properties
       -->Project1.csproj
       -->Project1Main.cs

   -->Project2Folder
       -->bin
       -->object
       -->Properties
       -->Project2.csproj
       -->Project2Main.cs

So the question again: Why do I only see StyleCop violations and no violation from FxCop, Gendarme and so on?

I also want to add my sonar-project.properties:

# optional description
sonar.projectDescription=Project description

# Project identification  
sonar.projectKey=Vendor:Project
sonar.projectVersion= 1.0
sonar.projectName= Project 

# Info required for Sonar  
sources=.
sonar.language=cs
sonar.sourceEncoding=UTF-8

#Core C# Settings  
sonar.dotnet.visualstudio.solution.file=Project.sln
2

2 Answers

1
votes
  • First you should not put project specific settings in the sonar-runner.properties file, you should create a "sonar-project.properties" file inside your solution and keep it there

  • Second, in this "sonar-project.properties" file, "sonar.sources" should be set to "." and you shouldn't have "sonar.tests" nor "sonar.binaries"

All this is well explained in the documentation and applied in the sample project.

0
votes

I just found the solution.

Fabrice - Sonar Team just brought me to this thought, that FxCop and Gendarme could not work correctly because they have no assambly to work with.

Here I found the soultion. FxCop just searches for assamblies in the Debug folder, and because I just had my assamblies in the release folder it did not work properly. So I changed them back to Debug (or sonar.dotnet.buildConfigurations propery) to solve it