Core Components (layered from bottom-up):
- Compilers (
src/Compilers/): C# and VB.NET compilers with syntax trees, semantic models, symbols, and emit APIs - Workspaces (
src/Workspaces/): Solution/project model, document management, and host services - Features (
src/Features/): Language-agnostic IDE features (refactoring, completion, diagnostics) - EditorFeatures (
src/EditorFeatures/): Editor-specific implementations and text buffer integration - VisualStudio (
src/VisualStudio/): VS-specific language services and UI integration
Building:
build.sh- Full solution builddotnet build Compilers.slnf- Compiler-only builddotnet msbuild <path to csproj> /t:UpdateXlf- Update .xlf files when their corresponding .resx file is modified
Testing:
test.sh- Run all testsdotnet testfor specific test projects- Tests inherit from base classes like
AbstractLanguageServerProtocolTests,WorkspaceTestBase - Use
[UseExportProvider]for MEF-dependent tests
Formatting:
- Whitespace formatting preferences are stored in the
.editorconfigfile - When running
dotnet format whitespaceuse the--folder .option followed by--include <relative path to file>to avoid a design-time build. dotnet format whitespace --folder . --include <relative path to file>- Applies formatting preferences to a particular .cs or .vb file
Service Architecture (use MEF consistently):
[ExportLanguageService(typeof(IMyService), LanguageNames.CSharp), Shared]
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed class CSharpMyService : IMyServiceRoslyn API Usage:
// Always use immutable patterns
var newTree = oldTree.WithChangedText(newText);
var newDocument = oldDocument.WithSyntaxTree(newTree);
// Semantic analysis
var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
var symbolInfo = semanticModel.GetSymbolInfo(expression);Testing Conventions:
- Inherit from
TestBaseor language-specific base classes - Use
UseExportProviderfor MEF services - Test utilities in
Microsoft.CodeAnalysis.Test.Utilities - Language-specific test bases:
CSharpTestBase,VisualBasicTestBase - Add
[WorkItem("https://github.com/dotnet/roslyn/issues/issueNumber")]attribute to tests that fix specific GitHub issues
- Language Server Protocol:
src/LanguageServer/contains LSP implementation used by VS Code extension - ServiceHub: Remote services (
src/Workspaces/Remote/) run out-of-process for performance - Analyzers:
src/Analyzers/for static analysis, separate fromsrc/RoslynAnalyzers/(internal tooling) - VSIX Packaging: Multiple deployment targets -
src/VisualStudio/Setup/for main VS integration
- Namespace Strategy:
Microsoft.CodeAnalysis.[Language].[Area](e.g.,Microsoft.CodeAnalysis.CSharp.Formatting) - File Organization: Group by feature area, separate language-specific implementations
- Immutability: All syntax trees, documents, and solutions are immutable - create new instances for changes
- Cancellation: Always thread
CancellationTokenthrough async operations - MEF Lifecycle: Use
[ImportingConstructor]with obsolete attribute for MEF v2 compatibility - PROTOTYPE Comments: Only used to track follow-up work in feature branches and are disallowed in main branch
- Code Formatting: Avoid trailing spaces and blank lines (lines with only whitespace). Ensure all lines either have content or are completely empty.
- Follow existing conventions in the file
- Language services must be exported per-language, not shared across C#/VB
- Test failures often indicate MEF composition issues - check export attributes
- VSIX deployment targets multiple architectures - ensure platform-specific assets are handled
- ServiceHub components require special deployment considerations for .NET Core vs Framework
docs/wiki/Roslyn-Overview.md- Architecture deep-divedocs/contributing/Building, Debugging, and Testing on Unix.md- Development setupsrc/Compilers/Core/Portable/- Core compiler APIssrc/Workspaces/Core/Portable/- Workspace object model- Solution filters:
Roslyn.sln,Compilers.slnf,Ide.slnffor focused builds