Esta página se muestra en inglés. Una traducción al español está en curso.
ScriptsJul 17, 2026·3 min de lectura

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.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
Roslyn Overview
Comando de instalación directa
npx -y tokrepo@latest install bad06c31-819a-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con 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

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados