A code analyzer examines your source code and reports diagnostics to help find errors or enforce rules. A source generator runs during compilation and creates additional source code that becomes part of your program.
In the C#/.NET ecosystem, source generators and analyzers are both built on the same Roslyn compiler platform, and analyzers are typically referred to as Roslyn analyzers.
Both analyzers and source generators are imported as managed plugins to your Unity project. You can either write your own analyzer or source generator or import existing third party libraries.
Note: Roslyn analyzers are only compatible with the IDEs that Unity supports.
For more information about how to write and use Roslyn analyzers, refer to Analyzer Configuration and Get started with Roslyn analyzers in the Microsoft documentation.
| Topic | Description |
|---|---|
| Create and use a source generator | Create a simple source generator and configure the Unity Editor to use it for your Unity project code. |
| Create and use a Roslyn analyzer | Create a simple Roslyn analyzer and configure the Unity Editor to use it for your Unity project code. |
| Install and use an existing analyzer or source generator | Download an existing code analyzer or source generator and configure the Unity Editor to use it for your Unity project code. |
| Additional files for Roslyn analyzers and source generators | Define additional text files for Roslyn analyzers or source generators to use. |
| Analyzer scope and rule set files | Control which parts of your code are subject to code analysis and customize diagnostic levels per-assembly. |