Configuring Roslyn

It is possible to incorporate Roslyn results in the TICS output for C# files. Roslyn also known as the .NET Compiler Platform. It provides some code analysis APIs in which the TICS C# Coding Standard has been implemented.

Prerequisites

For a successful Roslyn integration, the following prerequisites must be met.

Basic configuration

The Roslyn analyzer requires the BUILDTYPE to be properly set.

A standard Roslyn rule configuration is available in the form of a IMPL.txt, RULES.txt pair.

Optional configuration

The configuration for Roslyn can be added to either the SERVER.txt to apply them for all projects, or in PROJECTS.txt to enable project-specific settings. If the properties are declared in the SERVER file and also in the PROJECT file, the project-specific properties will override the global properties.

Syntax
'TOOLS' => {
  'Roslyn' => {
    'ANALYSISMODE' => 'FILE|MULTIFILE|SOLUTION', # default: MULTIFILE
  }
}

Roslyn can analyze C# code in three different analysis modes. Each of these modes has its own strengths and weaknesses.

File-based analysis

The most basic of the analysis modes is file-based analysis. In this mode, each file is analyzed separately. Since this is the most simple analysis mode, it is extremely stable and will work in almost any context. Since it considers each file in isolation, it is also relatively fast when analyzing a small number of files. The downside of this mode is that its lack of context can result in false positives and false negatives in cases where a coding standard rule needs context outside of a single file.

Multifile-based analysis

The default analysis mode is multifile-based analysis. This mode is similar to file-based analysis, but it runs the tool on multiple files at once. This mode relies on the build integration in order to retrieve the files within the same project. As a result, it will run faster as the number of files increases and will result in a smaller number of false positives and false negatives than the file-based analysis.

Solution-based analysis

Finally, Roslyn can run on an entire Visual Studio solution at once. This will result in the best possible results, since all source files and dependencies are taken into account. However, it also has the strictest requirements in terms of available build tools. At the very least, a recent version of Visual Studio along with all of the required plugins and libraries that are used by the project is required. This most is also typically the slowest. For these reasons, this is not the default mode.