Roslyn Compiler Platform
repository·main·Indexed 12 days ago
https://github.com/dotnet/roslynOpen-source implementation of the C# and Visual Basic compilers. It provides a rich API surface for building advanced code analysis tools, IDE features, and compilers. Includes documentation on compiler specifications, breaking changes across .NET and Visual Studio versions, and specialized analyzer packages like Microsoft.CodeAnalysis.BannedApiAnalyzers and Microsoft.CodeAnalysis.PublicApiAnalyzers.
What's inside Roslyn
- The Roslyn compiler provides Toolset NuGet packages that allow developers to override the default Roslyn compiler provided by MSBuild or the .NET SDK. Installing these packages instructs the MSBuild engine to use the version of the Roslyn build tasks and compilers contained within the package instead of the locally installed ones.
Overview of dotnet-roslyn-manifest-generator
mainThedotnet-roslyn-manifest-generatoris a tool used within the Roslyn ecosystem, specifically related to the Terrapin compiler infrastructure. It is responsible for generating artifacts manifests, which are used to track and manage build artifacts in the Terrapin environment.Overview of the Razor-Compiler
mainThe Razor-Compiler provides the parser and the C# code generator for the Razor syntax. Razor is a syntax designed to combine server-side code with HTML to create dynamic web content in a fast, terse, and lightweight manner.Overview of ASP.NET Core Razor
mainThis repository contains the open-source implementation of the Razor experience for ASP.NET Core. It provides the compiler and the IDE tools necessary for developing Razor-based ASP.NET Core applications. These tools are integrated into Visual Studio and Visual Studio Code.What is the Syntax API?
mainThe Syntax API provides access to the exact same parsers, data structures, and algorithms used by the Visual Basic and C# compilers. It allows developers to analyze, reason about, and construct syntax trees that represent code with full fidelity.
Key characteristics include:
- Full Fidelity: Every bit of information, including whitespace and comments, is represented.
- Immutability: Syntax trees cannot be changed once created, making them inherently thread-safe for concurrent analysis.
Overview of Incremental Generators
mainIncremental generators are a high-performance API designed to replace the original
ISourceGenerator(v1 source generators). They allow developers to define fine-grained generation strategies that the hosting layer (like Visual Studio) can execute efficiently by exploiting caching between steps.Key benefits include:
- Scalability: Designed to support massive projects at the scale of Roslyn/CoreCLR.
- Performance: Uses a pipeline-based approach to reduce duplicate work through caching.
- Extensibility: Supports generating items beyond just source text.
- Compatibility: Can coexist with existing
ISourceGeneratorimplementations.
Use Roslyn.Diagnostics.Analyzers for Roslyn repository development
mainThe
Roslyn.Diagnostics.Analyzerspackage contains rules specific to thedotnet/roslynrepository.Warning: This analyzer package is not intended for general consumption outside of the Roslyn repository.
Understand the Roslyn testing categories
mainRoslyn testing is categorized into three main types depending on the development lifecycle stage:
- Routine Product Testing: Focuses on features marked with the
:mag:tag. These are scenarios regularly tested against internal builds. - Release Testing: Involves testing all product features across all supported languages.
- New Language Feature Testing: A multi-phase process for evaluating new language syntax or rules.
New Language Feature Testing Phases
- Merge Signoff: Determines if a feature is ready to be merged. Critical IDE features in Typing, Navigating, and Viewing (marked with
:fast_forward:) must function correctly. Any non-trivial issues in these areas are considered merge-blocking. All features must be free of crashes, asserts, and hangs. - Feature Signoff: Per-feature signoff that includes links to any remaining non-blocking issues.
- Feature Suggestions: Brainstorming enhancements to make the new language feature more delightful for users.
- Routine Product Testing: Focuses on features marked with the
Identify banned APIs with Microsoft.CodeAnalysis.BannedApiAnalyzers
mainTheMicrosoft.CodeAnalysis.BannedApiAnalyzerspackage provides customizable rules to identify and flag references to specific APIs that have been banned in your codebase. This is useful for enforcing architectural constraints or preventing the use of deprecated/unsafe methods.Monitor public API changes with Microsoft.CodeAnalysis.PublicApiAnalyzers
mainTheMicrosoft.CodeAnalysis.PublicApiAnalyzerspackage is designed for library authors. It provides rules to help monitor and detect changes to public APIs, ensuring that breaking changes are caught during the development process.Use Replay to profile compiler performance
mainReplay is a tool designed to replay compilation events from an MSBuild binary log directly into the compiler server. This process removes MSBuild overhead from the logs, providing a cleaner view of compiler performance. It is also useful for comparing performance changes between different code branches by running the same binary log against both.
dotnet run --framework net472 --configuration Release <path-to-binlog>Understand the purpose of Legacy Razor SpanEditHandler verification tests
mainThe legacy Razor SpanEditHandler verification tests are used to ensure that the compiler continues to produceSpanEditHandlersin the specific locations required by the WebTools editor. These tests are derived from the standard Razor test files to maintain backward compatibility for editor tooling.