Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 32 Next »

Create a Sonar file for your solution

Here is the simplest "sonar-project.properties" file that you can write to be able to run a Sonar analysis for your project:

"sonar-project.properties" file for the Sonar Runner

The "sonar.projectKey" parameter will create a unique identifier in Sonar for your C# solution.

File location

Icon

The Sonar configuration file should be placed at the root of your Solution. This way, Sonar will automatically discover the ".sln" file located in this folder.
If the SLN file is elsewhere, then you can add the "sonar.dotnet.visualstudio.solution.file" properties to specify its relative path, but we do recommend you to follow our best-practices.

Icon

If you decide to use Maven instead of the Sonar Runner, please refer to the "C# Plugins and Maven" page.

Your .NET solution must be compiled if you want to use the following plugins:

  • FxCop
  • Gendarme
  • Gallio
  • NDeps

C# plugins options

Every C# plugin defines its own options that can be overridden, may it be through the Sonar configuration file that you've just created or through Sonar "System Settings" web page. You will find below the pages that describe each C# plugin options:

Paths and File Patterns

Each time you need to define the location of a file or a set of files, use '/' instead of '\' (even if that looks weird on a windows box)
If you need to specify a path, this path may be absolute or relative. Relative paths may start from the location of the sln file or the csproj files, depending of the property specified. Relative paths may use "../" to climb in the folder hierarchy.
When several files need to be specified, for example for properties such as "sonar.dotnet.assemblies", "Ant style" wildcard patterns can be used. "*" means any file or any directory. "**" means any directory and subdirectory :

Above pattern will select any dll files prefixed by "Foo" anywhere in a project.
You can combine an absolute path prefix with wildcards :

This will select any dll files in any subfolder of the "lib" folder of the drive "T:".

If you need to reference assembly files outside your solution folder, you can use absolute paths or "../". For example :

Above pattern can be used to specify all the dll files of a lib folder located at the same level as the root folder of your visual studio solution.

As of version 1.4, $(SolutionDir) is not the only special expression that can be used in file patterns. Below the exhaustive list of supported expressions:

ExpressionDescription
$(SolutionDir)Root directory of the solution, this is the directory where the sln file used by sonar is located
$(ProjectName)Name of the currently analysed project of the solution.
$(AssemblyName)Name of the assembly generated by the currently analysed solution. Works only for non asp projects.
$(AssemblyVersion)Version of the assembly generated by the currently analysed solution.
$(OutputType)Type of the generated assembly. Can be "dll" or "exe"
$(RootNamespace)Root namespace of the currently analysed project.

So if the solution you need to analyze use a "post compilation" msbuild/nant task that copies the generated assemblies somewhere into a "BUILD" directory, you can set the property "sonar.dotnet.assemblies" with this pattern:

Tools such as Gendarme and FxCop will be executed once for each project of the solution. For each project, the expressions "AssemblyName" and "OutputType" will be evaluated in order to locate the project assembly.

 

 

  • No labels