SourceGenerator Framework
SourceGenerator Framework Wiki
Section titled “SourceGenerator Framework Wiki”This wiki is the project documentation hub for Purview.SourceGeneratorFramework — a strongly typed
framework for building, testing, and maintaining incremental C# source generators with Roslyn. It
includes structured code generation (CodeWriter), incremental pipeline helpers, attribute data
models, type libraries, a step-cache test runner for verifying incremental behaviour, and bundled
analysers that guide generators back to best practice.
Start here
Section titled “Start here”- Getting Started
- Source Generator & Analyser Best Practices
- CodeWriter structured API reference
- TypeLibraryGenerator
- Attribute Data Models
- Incremental Pipeline
- Analyzers
- Testing
- Testing with TUnit
- Step-Cache Tests
- Packaging
- Performance
- Release Flow
Packages
Section titled “Packages”| Package | Description | Packable |
|---|---|---|
Purview.SourceGeneratorFramework |
Core helpers, models, and MSBuild integration for writing incremental source generators. | Yes |
Purview.SourceGeneratorFramework.Testing |
Framework-agnostic test runner and assertions for source generator unit tests. | Yes |
Purview.SourceGeneratorFramework.Testing.TUnit |
TUnit-specific test base classes and assertions for source generator tests. | Yes |
Purview.SourceGeneratorFramework.Generators |
Internal Roslyn source generator used by the framework package. | No |
Purview.SourceGeneratorFramework.ExampleGenerator |
Reference implementation showing how to build a generator with the framework. | No |
Feature highlights
Section titled “Feature highlights”CodeWriter— an allocation-conscious writer for generated C# source with indentation, namespace/type declarations, structured statements, XML documentation, conditional compilation blocks, and deterministic output. Declarations and statements are structured values rather than raw text; see Code-Writer.md.IncrementalPipeline— extension methods for composingIncrementalValueProvider<T>/IncrementalValuesProvider<T>pipelines, including attribute-based discovery, generation-context creation, and disable-property checks; see Incremental-Pipeline.md.GenerationContext— a base execution-services context carrying the RoslynCompilation, immutable generator settings, optional logging, and a factory for independently ownedCodeWriterinstances.GeneratorResult<T>— a value-or-diagnostics result type for incremental transforms, with explicit per-diagnosticIsBlockingcontrol over whether generation continues.AttributeDataModelGenerator— bundled generator that emitsreadonly record structattribute parser models from[Generate]declarations; see Attribute-Data-Models.md.TypeLibraryGenerator— generates a self-containedpublic static partialtype library from a small declarative spec; see Type-Library.md.- Bundled analysers and code fixes —
PSGFR11–PSGFR38diagnostics for Roslyn best practice, plus code fixes; see Analyzers.md. - Testing framework —
SourceGeneratorTestRunner<TGenerator>,CodeQuerysyntax-node assertions, refactoring tests, and incremental cache tests; see Testing.md and Testing-TUnit.md. - Step-cache tests — prove a generator caches correctly stage-by-stage; see Step-Cache-Tests.md.
Requirements
Section titled “Requirements”- .NET SDK 10.0 or later to build the framework.
- The framework is built against Roslyn 5.0 (
Microsoft.CodeAnalysis5.x), so compiler hosts that load the generator, analyser, and testing assemblies must be Roslyn 5.0 or later (.NET 10SDK / Visual Studio 2026 18.0). - Source generators target
netstandard2.0; test projects targetnet8.0,net9.0, andnet10.0.
Repository layout
Section titled “Repository layout”src/src/SourceGeneratorFramework— core framework package.src/src/SourceGeneratorFramework.Generators— bundled generators (attribute data models, type library), shipped inside the core package.src/src/SourceGeneratorFramework.Analyzers— bundled analysers.src/src/SourceGeneratorFramework.CodeFixers— bundled code fix providers.src/src/SourceGeneratorFramework.Testing— framework-agnostic testing package.src/src/SourceGeneratorFramework.Testing.TUnit— TUnit testing integration.src/src/SourceGeneratorFramework.ExampleGenerator— reference generator implementation.src/src/SourceGeneratorFramework.Benchmarks— BenchmarkDotNet benchmarks (see Performance.md).