Skip to content
Andrew Best edited this page Sep 9, 2016 · 5 revisions

Roslyn conventions leverage roslyn diagnostic analyzers to analyze the code that makes up a codebase in a syntax-tree format, as opposed to Solution conventions which work with the raw text that comprises the solution.

All roslyn conventions derive from SolutionDiagnosticAnalyzerConventionSpecification

To install from NuGet

Roslyn conventions are available in a separate package to keep the dependency weight of Best.Conventional to a minimum. To access the Roslyn conventions, or build your own, you will need to

Install-Package Best.Conventional.Roslyn

Configuration

Roslyn-based conventions need to know what solution they will be working with, and this can be set in one of two ways. The first is to simply set your solution root, and let Conventional do a recursive search from there for the first .sln file it can find

KnownPaths.SolutionRoot = @"c:\projects\MySolutionRoot"

The other option, if you happen to have a slightly more complex composition, is to set the full path to the solution like so

KnownPaths.FullPathToSolution = @"c:\projects\MySolutionRoot\MySolution.sln"

Sample Usage

ThisCodebase
    .MustConformTo(RoslynConvention.IfAndElseMustHaveBraces)
    .WithFailureAssertion(Assert.Fail);

Supplied Roslyn Conventions

  • If and Else must have braces
  • Using statements must not be nested