A Source Generator is a piece of code that runs during compilation and can inspect your program to produce additional files that are compiled together with the rest of your code.Ī Source Generator is a new kind of component that C# developers can write that lets you do two major things: Unless you’ve been closely following every prototype and proposal related to the C# language and compiler, then there’s a good chance you’re asking, “What is a Source Generator” right now. Note: to build a source generator, you currently require Visual Studio. NET 5 preview and the latest Visual Studio preview. To get started with Source Generators, you’ll need to install the latest. This is done via a new kind of component that we’re calling a Source Generator.
We’re pleased to introduce the first preview of Source Generators, a new C# compiler feature that lets C# developers inspect user code and generate new C# source files that can be added to a compilation.