In this post I want to describe step by step process of Sonar installation for .Net .

Sonar ?

Basically  Sonar is web application that gathers data from various analytical tools available on .Net, Java etc.

In .Net environment we can provide data from for example:

  • FxCop
  • StyleCop
  • Open Cover

How does it look like ?. Check this online repository of one of the open source projects.

 

Installation

 

  1. What do I need
    • Sonar 
    • Sonar C# Ecosystem + Plugins
    • Sonar Runner
    • Java JDK
    • Database
      • you can use embedded DB but this one is not recommended for bigger projects
      • MySql is proffered DB engine, Sonar is based on Java and its driver for MsSql doesn’t work. I tried to run it on MsSql but -unfortunately right now I wasn’t able to do this.
    • Analytical tools
  2. Copy sonar to some folder let’s say C:\sonar
  3. Copy sonar runner to some folder let’s say C:\sonarrunner
  4. Install JDK
  5. Install OpenCover
  6. Install Gallio
  7. Configure user Variables. Add These Values
    • SONAR_RUNNER_HOME – path to sonar runner (eg: C:\sonarrunner )
    • JAVA_HOME – path to jdk (eg: C:\Program Files\Java\jdk1.7.0_03)
    • Path – Add path to Gallilo and sonarrrunner (eg:C:\Program Files\Gallio\bin;C:\sonarrunner\bin; )
  8. Configure Sonar DB access
    • Locate file sonar.properties (eg: c:\sonar\conf ). I n this file you will find various settings. What we want right now is to set up connection to our DB. Locate value sonar.jdbc.url. We will configure our sonar to use embedded DB. In order to do that locate Comment that explains Embedded DB connection and make sure that sonar.jdb.url: value is uncommented
    • If you want to use MySql comment out embedded database connection and uncomment MySql connection. Make sure that Port is ok and Crendentials are ok
  9. Installing C# Ecosystem + Plugins
    • copy all the files to (eg: C:\sonar\extensions\plugins )
  10. Running Sonar
    • go to your sonar installation folder
    • locate bin folder
    • go to  folder with your operating system
    • run StartSonar.bat
    • wait 1-2 minutes and check http://localhost:9000/sonar
    • if everything went ok you should see sonar starting page
  11. Configuring Plugins
    • Log in as login : admin, password : admin
    • Go to Configuration
    • On the right side go to General Settings. Here you will find different Categories.
      • C# Core
        • Here you can setup path to .Net libraries. If you have them in default folders don’t change anything.
      • C# FxCop
        • point “FxCop installation directory” to your installation folder (eg: C:\Program Files (x86)\Microsoft FxCop 1.36)
      • C# Gallio
        • point “OpenCover install directory” to your installation folder ( eg: C:\Users\mfc\AppData\Local\Apps\OpenCover),
        • point Gallio install directory to your installation folder
        • Change Coverage tool to “OpenCover”
      • C# StyleCop
        • As before point StyleCop Installation folder (eg : C:\Program Files (x86)\Microsoft StyleCop 4.3.3.0 )
  12. Configuring Project File
    • Each project needs his own configuration file.
    • Go to your solution folder ( *.sln file has to be in this folder )
    • Add two files:
      • sonar-project.properties# Project identification sonar.projectKey=( project key eg: MyCompany:Console_App ) sonar.projectVersion= ( project version ) sonar.projectName= ( project name displayed in dashboard eg: Console_App ) # Info required for Sonar sonar.sources=. 
        sonar.language=cs
        sonar.dotnet.visualstudio.solution.file= ( solution name eg : ConsoleApp.sln ) sonar.donet.visualstudio.testProjectPattern=( part of the name projects containg unit tests eg : *.Tests )
      • sonar-project-run.bat
      • run here just sonar-runner ( if you configured path correctly )
  13. Running Sonar Analysis
    • execute sonar-project-run.bat – remember that instance of Sonar has to be running !

Helpful links

http://stackoverflow.com/questions/4791051/sonar-installation-problem

http://stackoverflow.com/questions/8095485/error-running-sonar-connected-to-sql-server-2005-sonar-dbo-rules-for-column-des

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=11774

http://resources.visual-paradigm.com/index.php/tips-support/53-support/95-sql-connection-problem.html