sonar for c# on windows
Sonar is a shiny dashboard for code quality that provides an integration point for various quality frameworks (FxCop, StyleCop, NCover, Gallio, Gendarme etc). Unfortunately (like most awesome tools), its native to the JVM but there are actively maintained plugins for .NET.
So here’s a quick rundown for how I got it running on my local machine:
- Install Sonar - http://docs.codehaus.org/display/SONAR/Install+Sonar
- Install requirements
- Make sure java.exe is in your search PATH (C:\Program Files (x86)\Java\jre6\bin)
- Tomcat - run as exe or install as service
- DB not required for demo but would for proper installation (MSSQL, MySql, Postgres etc)
- Unzip (c:\sonar)
- Run via c:\sonar-2.11\bin\windows-x86-32\StartSonar.bat
- Wait a few minutes for the JVM to spin up and create a local DB (/data)
- You can watch this via /logs/sonar.log
- Install requirements
- Install Sonar-runner (so we can run it without Maven) - http://docs.codehaus.org/display/SONAR/Analyse+with+a+simple+Java+Runner
- Set your JAVA_HOME (C:\Program Files (x86)\Java\jre6)
- (Optional) Copy the jdbc settings from sonar.properties to sonar-runner.properties
-
sonar.jdbc.url: jdbc:derby://localhost:1527/sonar;create=true
sonar.jdbc.driverClassName: org.apache.derby.jdbc.ClientDriver
-
- Add C:\sonar-runner-1.1\bin to your PATH
- To test: sonar-runner -h
- Follow the C# plugin walkthrough here: http://docs.codehaus.org/display/SONAR/C-Sharp+Plugins+Ecosystem
- Download http://docs.codehaus.org/download/attachments/201228384/CSharpPluginsEcosystem-1.1.zip
- Extract to C:\sonar-2.11\extensions\plugins
- (Remove gallio & fxcop jars unless you’ve installed their binaries separately)
- Restart Sonar
- Create a sonar config in your .sln directory http://docs.codehaus.org/display/SONAR/2.+Configure#2.Configure-CreateaSonarfileforyoursolution
- Create sonar-project.properties & paste skeleton config
- cd to your .sln directory
- Run sonar-runner from cmd
- Bask in the shiny graphs
Some interesting things I’m still to do…
- Add Gallio with (PartCover|NCover) for unit test coverage
- Figure how to integrate it into the CI process
- “Stop the line” on certain metrics?