Annotations in Source Code
The easiest way to benefit from Rider's code annotations is to add the annotation attributes to symbols of your source code and make Rider analyze your solution with greater accuracy and insight.
By default, all annotation attribute classes are marked with
[Conditional("JETBRAINS_ANNOTATIONS")] so the compiler will ignore the attribute usages in your code, which means that no binary reference to the 'JetBrains.Annotations.dll' assembly will be produced. However, you can define 'JETBRAINS_ANNOTATIONS' conditional compilation symbol in your projects to preserve the attributes in metadata.
Enabling Rider code annotations support in your project
To make use of Rider code annotation attributes in your project, you should reference them in one of the following ways:
- The recommended way is to install the NuGet package with the
- You can simply add a project reference to the JetBrains.Annotations.dll, which you can find in the Rider installation directory.
If the JetBrains.Annotations.dll is referenced or attribute declarations are inserted in any of the projects within your solution, you can type the desired annotation attribute and press Alt+Enter to invoke the quick-fix that will reference this module in the current project and add the missing namespace import directive:
Using Context Actions to add annotation attributes
As soon as Rider is aware of annotation classes location, you can use context actions to add the most popular annotation attributes:
To add these annotations, press Alt+Enter on the symbol you want to annotate, and Rider will suggest an attribute depending on the context: