Purview.SourceGeneratorFramework
1.0.0-prerelease.6
See the version list below for details.
dotnet add package Purview.SourceGeneratorFramework --version 1.0.0-prerelease.6
NuGet\Install-Package Purview.SourceGeneratorFramework -Version 1.0.0-prerelease.6
<PackageReference Include="Purview.SourceGeneratorFramework" Version="1.0.0-prerelease.6" />
<PackageVersion Include="Purview.SourceGeneratorFramework" Version="1.0.0-prerelease.6" />
<PackageReference Include="Purview.SourceGeneratorFramework" />
paket add Purview.SourceGeneratorFramework --version 1.0.0-prerelease.6
#r "nuget: Purview.SourceGeneratorFramework, 1.0.0-prerelease.6"
#:package Purview.SourceGeneratorFramework@1.0.0-prerelease.6
#addin nuget:?package=Purview.SourceGeneratorFramework&version=1.0.0-prerelease.6&prerelease
#tool nuget:?package=Purview.SourceGeneratorFramework&version=1.0.0-prerelease.6&prerelease
Purview.SourceGeneratorFramework
Core helpers, models, and MSBuild integration for writing incremental C# source generators with Roslyn.
Installation
dotnet add package Purview.SourceGeneratorFramework
What's included
CodeWriter— allocation-conscious helper for building generated C# source files with indentation, namespaces, type declarations, comments, and XML documentation.IncrementalPipeline— extension methods for composingIncrementalValueProvider<T>andIncrementalValuesProvider<T>pipelines, including attribute-based discovery, generation context creation, and disable-property checks.GenerationContext— a base context record that carries the RoslynCompilationand a sharedCodeWriter.GeneratorResult<T>— a value-or-diagnostics result type for incremental source generator transforms.TypeValueObject,TargetSymbolDescriptor,EquatableArray<T>,DiagnosticInfo— reusable models for generator inputs and outputs.SymbolResolver,TypeHelpers,EmbeddedResources— helper classes for common symbol and resource tasks.- MSBuild
.props/.targets— automatically addsglobal usingdirectives for the main namespaces and supports packaging source generators that reference this framework.
Usage
Reference the package from a Roslyn source generator project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsRoslynComponent>true</IsRoslynComponent>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Purview.SourceGeneratorFramework" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
</ItemGroup>
</Project>
Implement IIncrementalGenerator and use the framework helpers to build a pipeline:
using Microsoft.CodeAnalysis;
using Purview.SourceGeneratorFramework.Helpers;
using Purview.SourceGeneratorFramework.Models;
[Generator]
public sealed class MyGenerator : IIncrementalGenerator
{
static readonly TypeValueObject AttributeType = new("MyAttribute", "MyNamespace");
public void Initialize(IncrementalGeneratorInitializationContext context)
{
var contextProvider = IncrementalPipeline.DefaultGenerationContextValueProvider(context);
var targets = IncrementalPipeline.ForAttributeWithMetadataName(
context,
AttributeType,
static (ctx, ct) => ctx.TargetSymbol.Name
);
context.RegisterSourceOutput(
targets.CombineWithContext(contextProvider),
static (spc, pair) =>
{
var (name, generationContext) = pair;
var writer = new CodeWriter();
writer.WriteAutoGeneratedHeader(nameof(MyGenerator));
writer.WriteFileScopedNamespace("MyNamespace");
using (writer.WriteClass($"public static partial class {name}"))
{
writer.WriteLine("// generated content");
}
spc.AddSource($"{name}.g.cs", writer.ToString());
}
);
}
}
See SourceGeneratorFramework.ExampleGenerator for a complete reference implementation.
Disabling a generator at build time
Use IncrementalPipeline.IsDisabledValueProvider to read an MSBuild analyzer-config property and skip generation when it is set to true:
<PropertyGroup>
<MyGenerator_Disable>true</MyGenerator_Disable>
</PropertyGroup>
var isDisabled = IncrementalPipeline.IsDisabledValueProvider(context, "MyGenerator_Disable");
License
This project is licensed under the MIT license.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Purview.SourceGeneratorFramework:
| Package | Downloads |
|---|---|
|
Purview.SourceGeneratorFramework.Testing
Purview SourceGeneratorFramework libraries for building and testing incremental C# source generators. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-prerelease.25 | 54 | 8/27/2026 |
| 1.0.0-prerelease.24 | 65 | 8/19/2026 |
| 1.0.0-prerelease.23 | 66 | 8/19/2026 |
| 1.0.0-prerelease.22 | 68 | 8/19/2026 |
| 1.0.0-prerelease.21 | 66 | 8/18/2026 |
| 1.0.0-prerelease.20 | 71 | 8/18/2026 |
| 1.0.0-prerelease.19 | 72 | 8/17/2026 |
| 1.0.0-prerelease.18 | 73 | 8/16/2026 |
| 1.0.0-prerelease.17 | 64 | 8/14/2026 |
| 1.0.0-prerelease.16 | 64 | 8/13/2026 |
| 1.0.0-prerelease.15 | 65 | 8/13/2026 |
| 1.0.0-prerelease.14 | 60 | 8/13/2026 |
| 1.0.0-prerelease.13 | 66 | 8/13/2026 |
| 1.0.0-prerelease.12 | 68 | 8/12/2026 |
| 1.0.0-prerelease.11 | 65 | 8/12/2026 |
| 1.0.0-prerelease.10 | 60 | 8/12/2026 |
| 1.0.0-prerelease.9 | 75 | 8/11/2026 |
| 1.0.0-prerelease.7 | 68 | 8/9/2026 |
| 1.0.0-prerelease.6 | 65 | 8/8/2026 |
| 1.0.0-prerelease.5 | 62 | 8/7/2026 |