How dotnet/roslyn-analyzers works
This project is the “Roslyn Analyzers” repository – a large, multi-package code analysis suite that extends the Roslyn compiler platform by providing a wide range of analyzers, code fixes, refactorings, and testing utilities for .NET projects. Its primary purpose is to supply high-quality static analysis rules (such as CAxxxx rules) for code quality, performance, security, and design, and is delivered as several NuGet packages (for example, Microsoft.CodeAnalysis.NetAnalyzers).
Core Components & Analyzer Engines
• An “Analyzer Core” module that encapsulates the common infrastructure shared by all analyzer packages. This includes the core utilities under the “src/NetAnalyzers/Core” directory and shared analyzer metadata (like AnalyzerReleases, rule configurations, etc).
• Language-Specific Analyzers: Separate submodules for C# and Visual Basic. For instance, within “src/NetAnalyzers/CSharp” you see rules for code quality, API design, maintainability, performance, etc.; similarly, the “VisualBasic” directories contain VB–specific implementations.
• Specialized Analyzers for different target frameworks: Although the newer package consolidates most analyzers into Microsoft.CodeAnalysis.NetAnalyzers, legacy components and migration support still exist (e.g. the FxCopAnalyzers and the Microsoft.CodeQuality/NetCore/NetFramework.Analyzers components). A block for these can note target-specific behavior (bailing out when a checked API isn’t available).
Testing and Validation Infrastructure
• Unit Tests and Integration Tests: A large portion of the repository is dedicated to unit tests (e.g., “src/NetAnalyzers/UnitTests”) and performance tests (“src/PerformanceTests”) to validate the analyzers.
• Test Utilities and Frameworks: The “src/Test.Utilities”, “src/Utilities”, and various “FlowAnalysis” directories contain shared test code and utilities for verifying analyzer correctness.
• Code Metrics and Refactoring utilities: Components residing in “src/Utilities/Compiler”, “src/Utilities/FlowAnalysis”, and “src/Utilities/Refactoring” provide common functions that the analyzers and tests depend on.
Build, Automation, and CI/CD
• Build and Configuration: The repository includes several build scripts and configuration files (e.g., “build.cmd”, “Test.cmd”, “Restore.cmd”, “Directory.Build.props/targets”, and the “eng” folder with extensive cross-platform build scripts and pipeline templates). This block should show how source code is restored, compiled, and prepared for testing.
Packaging and Distribution
• Tools & Utilities: Under “src/Tools” you have programs for generating documentation, configuration files, and even performance diff utilities. These support both packaging and developer documentation.
Developer and External Interaction
• Documentation and Guidelines: The “docs” and “GuidelinesForNewRules.md” files support developer onboarding, suggesting that there is external documentation available for both users of the analyzers and contributors.
– Source code & configuration (repository “src”, “eng”, “docs”, etc.) → Build/CI processes.
– Build outputs → Generated NuGet packages → Integration with IDEs and Roslyn.
– Testing Utilities → Unit Tests running as part of CI.
• Callouts for important technologies:
– .NET SDK and Roslyn compiler platform for analyzer integration.
– CI/CD technologies (Azure Pipelines, GitHub workflows).
– NuGet as the distribution medium.