Skip to main content

Tips and Tricks to configure Sonar Qube for .NET projects (C#)

Last week’s I had the opportunity to configure Sonar for a pretty big project. The application has over 3M lines of code and use different languages and technologies, from C# and Silverlight to JavaScript, C++ and embedded applications.
The main scope was to see if we can configure Sonar for this project. We decided at this step to exclude the embedded part of the application for Sonar. This was decided because of the time limitations. I’m almost sure that we can configure Sonar for embedded part without any kind of problems.
In the next part of the post I will present different issues that I encountered during Sonar configuration.
Where to store custom configuration?
Sonar gives you the possibility to specify different custom configuration at server level or on each project that is analyzed. Personally I prefer to have all the configuration (tools path location, unit tests projects pattern and so on) at project level – in sonar-project.properties file. For me is more easily to manage and if you have two different project that use two different tools, it will be very easily to configure them. Also, on Sonar server multiple person can have access and change the configuration (more teams on the same server). But at sonar-project.properties files, only the team that is working on the project will have access.
Where to put and store the plugins?
In Sonar, for each custom plugin you need to install or setup 3rd part applications or tools. First thing that you ask yourself where should I install and configure them.
I recommend to put all this tools in a folder called “Sonar-Plugins” or something similar. In this way if someone will need to check the plugins resources, change the configuration or configure a new Sonar server, it will be pretty easy to find all the resources and reconfigure them. Also, in this way it will be easier for you to manage them – you don’t need to search each tool in different folders.
What encoding should I set?
When you create the sonar-project.properties files don’t forget to set the encoding of source file to UTF-8. The default encoding is different from the one that is used in .NET projects.
sonar.sourceEncoding=UTF-8
How to exclude setup project?
If you have different project used to create the install package I recommend to use ssonar.exclusion  property. Using it, you can specify what folders to be excluded.
sonar.exclusions=Install/*
How to specify the project name that is displayed in the Sonar dashboard?
To be able to specify a custom name of the project, you need to use the following 3 properties available for this purpose:
sonar.projectKey=MyFooProject
sonar.projectVersion=1.0
sonar.projectName=MyFooProject
How to specify the SLN that needs to be used?
In the case you have the SLN project in different location that the sonar-project.properties or you have multiple SLN files under the same folder you can use the following property to specify exactly what SLN should be used:
sonar.dotnet.visualstudio.solution.file=MyFooProject.sln
Ho to specify the Silverlight installation directory?
If you installed Silverlight in a custom location or you have a 64 bits machines, that you will need to specify the location where Silverlight is installed. You can do as in the following example:
sonar.silverlight.3.mscorlib.location=c:/Program Files (x86)/Reference Assemblies/Microsoft/Framework/Silverlight/v3.0
sonar.silverlight.4.mscorlib.location=c:/Program Files (x86)/Reference Assemblies/Microsoft/Framework/Silverlight/v4.0
sonar.silverlight.5.mscorlib.location=c:/Program Files (x86)/Reference Assemblies/Microsoft/Framework/Silverlight/v5.0
How to specify what projects contains the unit tests?
In general Sonar will detect what are the projects that contains unit tests. In practice this is not happening. Because of this, you will need to specify the project pattern for projects that contains unit test. In the following example you all the projects that contains the ‘Test’ string will be processed as unit tests projects.
sonar.donet.visualstudio.testProjectPattern=*Test*
What is the configuration pattern when I need to configure different plugins?
All plugins has the same configurations (the general one). To access this properties, you need to use the following path:
sonar.[pluginName].[propertyName]=[value]
In the following example you can see an example that  specify the installation directory of a plugin.
sonar.stylecop.installDirectory=C:/Sonar/sonar-plugins/StyleCop
How to skip a specific plugin?
If you have a plugin that you don’t want to run you can set the mode of the plugin to ‘skip.
sonar.fxcop.mode=skip
How to specify the installation directory of a plugin?
The installdirectory property is you solution. Don’t forget to use ‘/’ and not ‘\’.
sonar.fxcop.installDirectory=c:/Program Files (x86)/Microsoft Fxcop 10.0

I hope that this tips helped you to configure Sonar.

Comments

  1. Thanks for the good tips. By the way, how do you specify skipProjectPattern for multiple patterns. For example, I want to skip any project that has word "contracts" or "entities" in its project name?

    ReplyDelete
  2. Can you have different stylecop settings for unit test and other project?

    ReplyDelete
    Replies
    1. By default is at project level. People usually forget this because they are using only a stylecop file. Take a look on http://blogs.msdn.com/b/sourceanalysis/archive/2008/05/25/managing-source-analysis-project-settings.aspx

      Delete

Post a Comment

Popular posts from this blog

Windows Docker Containers can make WIN32 API calls, use COM and ASP.NET WebForms

After the last post , I received two interesting questions related to Docker and Windows. People were interested if we do Win32 API calls from a Docker container and if there is support for COM. WIN32 Support To test calls to WIN32 API, let’s try to populate SYSTEM_INFO class. [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } ... [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); ... SYSTEM_INFO pSI = new SYSTEM_INFO(

Azure AD and AWS Cognito side-by-side

In the last few weeks, I was involved in multiple opportunities on Microsoft Azure and Amazon, where we had to analyse AWS Cognito, Azure AD and other solutions that are available on the market. I decided to consolidate in one post all features and differences that I identified for both of them that we should need to take into account. Take into account that Azure AD is an identity and access management services well integrated with Microsoft stack. In comparison, AWS Cognito is just a user sign-up, sign-in and access control and nothing more. The focus is not on the main features, is more on small things that can make a difference when you want to decide where we want to store and manage our users.  This information might be useful in the future when we need to decide where we want to keep and manage our users.  Feature Azure AD (B2C, B2C) AWS Cognito Access token lifetime Default 1h – the value is configurable 1h – cannot be modified

What to do when you hit the throughput limits of Azure Storage (Blobs)

In this post we will talk about how we can detect when we hit a throughput limit of Azure Storage and what we can do in that moment. Context If we take a look on Scalability Targets of Azure Storage ( https://azure.microsoft.com/en-us/documentation/articles/storage-scalability-targets/ ) we will observe that the limits are prety high. But, based on our business logic we can end up at this limits. If you create a system that is hitted by a high number of device, you can hit easily the total number of requests rate that can be done on a Storage Account. This limits on Azure is 20.000 IOPS (entities or messages per second) where (and this is very important) the size of the request is 1KB. Normally, if you make a load tests where 20.000 clients will hit different blobs storages from the same Azure Storage Account, this limits can be reached. How we can detect this problem? From client, we can detect that this limits was reached based on the HTTP error code that is returned by HTTP