Microsoft .NET Source Generators

Source Generators were introduced in .NET 5 and provide a powerful way to not only generate code but also improve performance. Microsoft describes them this way:

A Source Generator is a new kind of component that C# developers can write that lets you do two major things: Retrieve a compilation object that represents all user code that is being compiled. This object can be inspected, and you can write code that works with the syntax and semantic models for the code being compiled, just like with analyzers today. Generate C# source files that can be added to a compilation object during compilation. In other words, you can provide additional source code as input to a compilation while the code is being compiled.

I have been using them ever since they came out and plan to write my own that coincides with the coding standards in my book “Rock Your Code: Coding Standards for Microsoft .NET” available on

Since the .NET team does not list all the source generators that come out of the box, I have decided to write an article on each one that I can. I have asked the team to provide a list, but until then, I hope you will check back to this post often.

The Articles

Have you found a source generator that you really like, please send me info and I will possibly add them to this list. You can email me by going here:

Upcoming Articles

  • Regular Expression Source Generator
  • DLL Library Import

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.