dotnet-csharp-source-generators

Guide building and consuming Roslyn source generators in .NET.

Updated Aug 16, 2025
One-click install
npx skills add https://github.com/dodyg/blue-nile-pds --skill dotnet-csharp-source-generators-dodyg
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-csharp-source-generators
Source: https://github.com/dodyg/blue-nile-pds/tree/main/.agents/skills/dotnet-csharp-source-generators
Command: npx skills add https://github.com/dodyg/blue-nile-pds --skill dotnet-csharp-source-generators-dodyg

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Roslyn source generators can be complex to implement and reuse; this Skill provides practical guidance for both creating and consuming Roslyn source generators in .NET, covering incremental patterns, diagnostics, tests, and integration.

Core Features & Use Cases

  • Guidance for authoring IncrementalGenerator-based sources, syntax providers, semantic analysis, and emit patterns.
  • Guidance for consuming built-in generators such as GeneratedRegex, LoggerMessage, and System.Text.Json source generation.
  • Best practices for testing, packaging, and cross-referencing with existing libraries.

Quick Start

Create a minimal Roslyn generator project and verify it with a small sample.

Frequently Asked Questions about dotnet-csharp-source-generators

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a Roslyn source generator in .NET?

To build a Roslyn source generator, create a .NET project targeting netstandard2.0 and implement IncrementalGenerator patterns using syntax providers and semantic analysis to generate code at compile time.

How does an incremental generator differ from a standard source generator?

An incremental generator uses a pipeline of syntax providers and semantic analysis to cache and filter nodes, reducing redundant computations compared to standard source generators that re-evaluate entire syntax trees.

How do I test Roslyn source generators and diagnostics?

Testing Roslyn source generators involves verifying the generated C# source code and ensuring custom diagnostics are correctly reported during compilation, typically by validating generated output against expected syntax trees.

How do I use built-in source generators like GeneratedRegex and LoggerMessage?

Built-in source generators like GeneratedRegex and LoggerMessage are consumed by applying their specific attributes to C# methods, which automatically generates optimized source code during compilation without manual implementation.

Does a Roslyn source generator project need to target netstandard2.0?

Yes, Roslyn source generator projects must target netstandard2.0 to ensure compatibility with the compiler environment, allowing the generated analyzer to be loaded correctly across different .NET project versions.

What is the best way to package a Roslyn source generator for library users?

Packaging a Roslyn source generator for library users requires configuring the project as an analyzer, targeting netstandard2.0, and distributing it via NuGet so the compiler automatically loads the generator and runs diagnostics.