Skip to end of metadata
Go to start of metadata

Deprecated because StyleCop doesn't rely on Roslyn and is therefore not well-integrated into the Visual Studio 2015+ environment.

Description / Features

The plugin provides coding rules from StyleCop (at least version 4.7).

It is compatible with SonarC#.

Steps to Analyze a C# Project from the Command Line

  1. On the SonarQube server:
    1. Install the SonarQube Server (see Setup and Upgrade for more details)
    2. Install the C# Plugin v4.1+ and the StyleCop v1.1+ plugin (see Installing a Plugin for more details)
    3. Enable in your quality profile some rules provided by StyleCop.
  2. On the build / analysis machine install:
    1. StyleCop (at least version 4.7) and MSBuild (any version) on the machine(s) running the SonarQube analyses and set the path to:

      • MSBuild.exe via Settings > General Settings > C# > StyleCop > Path to MSBuild.exe

      • StyleCop.dll via Settings > General Settings > C# > StyleCop > Path to StyleCop.dll

    2. The SonarQube Scanner for MSBuild

    3. The Microsoft .NET Framework v4.5.2+
  3. On the build / analysis machine, run the build and analysis:
    1. Open a Developer Command Prompt for Visual Studio
    2. Put yourself in the root folder of the project you want to analyze
    3. Run the following commands:

      • Run the SonarQube runner preparation phase
        MSBuild.SonarQube.Runner.exe begin /k:"sonarqube_project_key" /n:"sonarqube_project_name" /v:"sonarqube_project_version"

      • Build the project, for example:
        "C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" /t:Rebuild
      • Run the SonarQube runner analysis closing phase
        MSBuild.SonarQube.Runner.exe end
  4. Follow the link provided at the end of the analysis to browse your project's quality in SonarQube UI.

Steps 1. and 2. need only to be performed once.

Steps 3. and 4. need to be performed for each new analysis.

Custom Rules

Custom StyleCop Rules are supported by the rule template "Template for custom StyleCop rules" (CustomRuleTemplate).

Known Limitation

(warning) StyleCop does not support yet the new C# 6.0 syntax, and therefore the StyleCop Plugin does not either. Until new versions of StyleCop and the StyleCop Plugin are released, all StyleCop rules must be disabled when analyzing C# 6.0 projects.

Note that SonarC# does support C# 6.0.


  • No labels