This project is read-only.

How to integrate the Sonar build activity

Install and configure Sonar

Install the sonar runner on your build server. This is way beyond this guide, you should go to the SonarQube web site for that :
You should make it running without TFS first on a test project.

You may also have a look at the guide I wrote for configuration Sonar:

Prepare the Sonar runner for the Sonar activity

The Sonar build activity will launch the sonnar-runner from the Solution folder during the build.
Before that, the file necessary for the sonar-runner can be optionnally generated :
  • if a exists already (from the source controller), nothing is generated and the file is taken as is
  • if no file is found, the template is processed

Here are the variables available in the template :
  • %BINARIES_DIRECTORY_PATH% : the binaries folder of the TFS build (as defined in the build process template)
  • %BINARIES_DIRECTORY_PATH_SLASH% : same path with slashes instead of backslashes (for Sonar)

Here's an example of a working sonar properties template format :

# Project identification

# Info required for Sonar

# If multiple solutions in folder, use the following line to disambiguate

# sonar.fxcop.mode=skip
# sonar.gendarme.mode=skip
# sonar.gallio.mode=skip
# sonar.ndeps.mode=skip
# sonar.squid.mode=skip
# sonar.stylecop.mode=skip

sonar.fxcop.installDirectory=D:/Sonar.Net/Microsoft Fxcop 10.0


sonar.gallio.filter=exclude Type:/\.Integration\./




Integrate the build activity in your build template

It is useful to add a global parameter (browsable) "Run Sonar Analysis" to enable Sonar to launch or not during a build.

You can read more about how to prepare build servers and integrate the activity in your builds here:

Typically pass these parameters to the build activity :
  • BuildWorkspace <- Workspace
  • FailBuildOnAlert <- True (When a critical alert is raised, the activity can detect it and volountarily fail, requires the Sonar Build Breaker plugin)
  • FailBuildOnError <- False (because Sonar may not be always available, you don't want all your builds down if Sonar is down, but it's up to you)
  • GeneratePropertiesIfMissing <- if the file is missing, generates one from the template
  • ProjectsToAnalyze <- BuildSettings.ProjectsToBuild
  • SonarPropertiesFileName <- ""
  • SonarPropertiesTemplatePath <- "D:\Sonar.Net\sonar-properties.template"
  • SonarRunnerPath <- "D:\Sonar.Net\"
  • BinariesDirectory <- BinariesDirectory

Analysis result

This activity requires the Sonar Build Breaker plugin to be installed on your Sonar server deployment in order to be able to break builds on Critical alerts.

FailBuildOnAlert (param) FailBuildOnError (param) Alerts in the build Any Sonar error
True True Failed Failed
True False Failed Partially Succeeded
False True Failed Failed
False False Partially Succeeded Partially Succeeded

Configure your build definition

You may want to disable unit tests execution now, since Sonar will do it (it's up to you if you want the coverage and test stuff in your Sonar portal).

Roadmap for this activity

Ability to pass sonar properties parameters from the build definition directly into the resulting sonar properties file.


Please for problems with Sonar and TFS and .NET in general have a look at the sonar-users mailing list.
Thanks !

Last edited Oct 27, 2013 at 9:55 PM by vlabatut, version 5


honestguy Dec 3, 2013 at 5:27 AM 
BuildWorkspace <- Workspace... Is not been recognized by Sonar activity. Am I missing something. Kindly help. Regards.

vlabatut Oct 27, 2013 at 9:56 PM 
Sorry, the VS 2010 activity has been merged only recently... It is available in the VS 2010 branch now!

graydo64 Oct 14, 2013 at 4:15 PM 
...OK, so the download works in IE. Will try to build from source.

graydo64 Oct 14, 2013 at 4:10 PM 
Same here - I can see all the code quality activities - CodeMetrics, NUnit, StatLight and VSTest but there's no Sonar activity. The link to download the source is broken too...

CSJones Oct 4, 2013 at 6:09 PM 
I've downloaded the lastest version to the TFS BuildExtensions but don't see the Sonar activity in any of the .dlls inthe zip file for VS2010. Is it named something besides sonar?