dotnet-source-generation-first

Review .NET code to prefer compile-time source generation over runtime reflection.

1|1|Updated Jan 3, 2026
One-click install
npx skills add https://github.com/mcj-coder/development-skills --skill dotnet-source-generation-first
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-source-generation-first
Source: https://github.com/mcj-coder/development-skills/tree/main/skills/dotnet-source-generation-first
Command: npx skills add https://github.com/mcj-coder/development-skills --skill dotnet-source-generation-first

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill helps developers avoid performance bottlenecks and AOT/trimming issues in .NET applications by prioritizing compile-time source generation over slower, runtime-based reflection or code generation.

Core Features & Use Cases

  • Enforces Source Generation: Guides developers to use libraries that generate code during compilation (e.g., for mapping, logging, regex).
  • Improves Performance & Compatibility: Reduces runtime overhead, improves startup times, and ensures better compatibility with Ahead-of-Time (AOT) compilation and assembly trimming.
  • Use Case: When building a new microservice, use this Skill to ensure that all DTO mapping and logging mechanisms are implemented using source generators, preventing future performance regressions and deployment issues.

Quick Start

Use the dotnet-source-generation-first skill to evaluate a new mapping library for a .NET project.

Frequently Asked Questions about dotnet-source-generation-first

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

FAQPage Schema
How do I fix .NET AOT compilation and trimming issues caused by runtime reflection?

Fix .NET AOT and trimming issues by replacing runtime reflection with compile-time source generation. This approach uses deterministic, compile-time verified code to eliminate trimming warnings and ensure Ahead-of-Time compatibility.

What's the best way to improve .NET startup performance for mapping and serialization?

Improve .NET startup performance by adopting source generators for mapping, serialization, and logging. Generating code at compile time removes runtime reflection overhead, significantly reducing application startup latency.

When do I need source generation instead of reflection in .NET applications?

You need source generation when building .NET applications that require high performance, AOT compatibility, or assembly trimming. It enforces compile-time code generation for cross-cutting concerns like regex and DTO mapping to prevent runtime bottlenecks.

Can I use runtime-based alternatives for cross-cutting concerns if I follow specific review rules?

Runtime-based alternatives are considered only if they strictly adhere to specific review rules enforced by this approach. However, compile-time source generation remains the primary guided implementation to ensure deterministic and verified code execution.

Does .NET source generation work with common logging and regex libraries?

Source generation works with common .NET cross-cutting concerns, guiding the implementation of compile-time verified code for logging and regex. This ensures better compatibility with AOT compilation and assembly trimming.

Why does runtime reflection cause performance bottlenecks in .NET microservices?

Runtime reflection causes performance bottlenecks in .NET microservices due to dynamic code execution overhead. Prioritizing compile-time source generation eliminates this runtime cost, improving startup times and preventing future performance regressions.