Adventures in .NET

Getting into Source Generators in .Net - .NET 210

Dec 17, 2024
Stefan Schranz, a software developer at TeamFior with expertise in .NET and React TypeScript, unpacks the fascinating world of source generators. He breaks down how they offer a powerful alternative to T4 templates and explains the setup process for beginners. Listeners will learn about key advantages, use cases, and the challenges of tooling and IDE integration. Stefan also shares his journey into development and his favorite Netflix shows, adding a personal touch to the tech talk!
Ask episode
AI Snips
Chapters
Transcript
Episode notes
INSIGHT

Source Generators vs. T4 Templates/Reflection

  • Source generators run during compilation, not at runtime like reflection or before/after like T4.
  • They hook into the compilation cycle, analyze code, generate new source, and feed it back into the compilation.
ADVICE

Getting Started with Source Generators

  • Create a .NET Standard 2.0 project for your source generator.
  • Reference Microsoft.CodeAnalysis.CSharp and Microsoft.CodeAnalysis.Analyzer NuGet packages.
ANECDOTE

Source Generators in a Legacy Project

  • Stefan used source generators to translate C++/CLI definitions to managed code models.
  • This solved the issue of generating excessive files with post-build steps, a common complaint from colleagues.
Get the Snipd Podcast app to discover more snips from this episode
Get the app