Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsJul 17, 2026·3 min de lecture

Roslyn — .NET Compiler Platform and Code Analysis Engine

The open-source compiler platform behind C# and Visual Basic, providing rich code analysis APIs for building developer tools, refactoring engines, and diagnostics.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Roslyn Overview
Commande d'installation directe
npx -y tokrepo@latest install bad06c31-819a-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

Roslyn is the open-source compiler platform for C# and Visual Basic .NET, developed by Microsoft. It exposes compiler internals as APIs, enabling developers to build analyzers, code fixes, refactoring tools, and entire IDE experiences on top of the compilation pipeline.

What Roslyn Does

  • Compiles C# and Visual Basic source code into .NET assemblies
  • Provides syntax trees, semantic models, and symbol APIs for deep code inspection
  • Powers real-time diagnostics and IntelliSense in Visual Studio and VS Code
  • Enables custom Roslyn Analyzers that enforce coding standards at build time
  • Supports source generators that emit C# code during compilation

Architecture Overview

Roslyn is structured as a layered pipeline: the Lexer tokenizes source text, the Parser builds immutable syntax trees, and the Binder resolves symbols to produce a semantic model. Analyzers plug into this pipeline via the Diagnostics API, while Source Generators hook into the compilation phase to inject synthesized code before final IL emission.

Self-Hosting and Configuration

  • Ships with the .NET SDK; no separate install is needed for compilation
  • Add analyzer NuGet packages to any .csproj via dotnet add package
  • Configure analyzer severity in .editorconfig or Directory.Build.props
  • Source generators are referenced as project analyzers in the csproj file
  • CI pipelines treat analyzer warnings as build errors via TreatWarningsAsErrors

Key Features

  • Immutable red-green syntax trees allow efficient incremental reparsing
  • Workspace APIs model entire solutions for cross-project refactoring
  • Scripting API enables evaluating C# expressions at runtime
  • Full fidelity round-tripping preserves whitespace and comments
  • Extensible diagnostic and code-fix infrastructure used by thousands of NuGet analyzers

Comparison with Similar Tools

  • TypeScript Compiler API — similar concept for JS/TS but limited semantic query depth compared to Roslyn
  • GCC/Clang — C/C++ compilers with plugin architectures, but no managed API layer
  • Babel — JavaScript transformer with AST plugins; lacks semantic type analysis
  • tree-sitter — fast incremental parser for editors but does not perform semantic binding

FAQ

Q: Do I need Visual Studio to use Roslyn? A: No. Roslyn ships with the .NET SDK and works from the command line, VS Code, or any CI system.

Q: What is the difference between an Analyzer and a Source Generator? A: An Analyzer inspects code and reports diagnostics; a Source Generator produces additional C# files during compilation without modifying existing source.

Q: Can Roslyn compile F#? A: No. F# has its own compiler (FSharp.Compiler.Service). Roslyn covers C# and Visual Basic only.

Q: Is Roslyn suitable for building a custom IDE? A: Yes. The Workspace and Language Server Protocol APIs provide the foundation for IntelliSense, go-to-definition, and rename across entire solutions.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires