.NET Compiler Platform (Roslyn) analyzers
JetBrains Rider provides over 2500 code inspections in all supported languages, but if this is not enough, JetBrains Rider allows you to additionally use .NET Compiler Platform (Roslyn) Analyzers.
These analyzers may be helpful for code analysis to deeper understand specific frameworks, as many teams are writing their own analyzers to provide additional tooling for the frameworks they build. For example the xUnit.net folks have a set of Roslyn-based analyzers that helps with things like making sure xUnit-specific Fact
methods do not have parameters.
Roslyn analyzer support is enabled by default. You can disable and configure it on the
page of JetBrains Rider settings Ctrl+Alt+S.When Roslyn analyzer support is enabled, Rider scans for installed Roslyn analyzers and displays all code inspections from discovered analysers on the settings page where you can change severity levels in the same way as for JetBrains Rider native inspections.
There are two ways to install Roslyn analyzers:
If the desired analyzer ships as a NuGet package, you can use JetBrains Rider’s NuGet client to find and install it.
For example, MicroSoft Roslyn analyzers can be added with the Microsoft.CodeAnalysis.NetAnalyzers NuGet package.
You can reference the analyzer's .dll in the project's .csproj file by adding
<Analyzer Include="path\to\analyzers.dll">
.
All code inspection features including quick-fixes and solution-wide analysis are also available for inspections from external analyzers.
External analyzers may also run as part of the project build. If an analyzer has a default severity of warning or error, it will display the corresponding issues in the build output.
Here is an example of installing and using the DisableDateTimeNow analyzer in a .NET Core web application. DisableDateTimeNow is a simple analyzer that finds usages of DateTime.Now
and suggests replacing them with DateTime.UtcNow
.
![JetBrains Rider: installing and using Roslyn analyzer](https://resources.jetbrains.com.cn/help/img/rider/2024.2/installing-roslyn-analyzer-in-rider.png)