In this post I want to describe step by step process of Sonar installation for .Net .
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:
- Open Cover
How does it look like ?. Check this online repository of one of the open source projects.
- What do I need
- Sonar C# Ecosystem + Plugins
- Sonar Runner
- Java JDK
- 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
- Copy sonar to some folder let’s say C:\sonar
- Copy sonar runner to some folder let’s say C:\sonarrunner
- Install JDK
- Install OpenCover
- Install Gallio
- 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; )
- 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
- Installing C# Ecosystem + Plugins
- copy all the files to (eg: C:\sonar\extensions\plugins )
- 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
- 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 18.104.22.168 )
- C# Core
- 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.language=cssonar.dotnet.visualstudio.solution.file= ( solution name eg : ConsoleApp.sln ) sonar.donet.visualstudio.testProjectPattern=( part of the name projects containg unit tests eg : *.Tests )
- run here just sonar-runner ( if you configured path correctly )
- 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=.
- Running Sonar Analysis
- execute sonar-project-run.bat – remember that instance of Sonar has to be running !