I’m currently writing my own Source generator which can become quite challenge. Yesterday I talked about RoslynQuoter as one of the tools that helped me along the way. Today I want to show you an easy way to get started thanks to the F0.Templates project.
Start by installing the F0.templates using dotnet new --install F0.Templates
:
Now create a new project using the installed RoslynGenerator template dotnet new roslyngenerator
.
This will create not only a SourceGenerator project but also a unit and integration tests project and a benchmark project:
Inside the projects we find a simple example of an incremental source generator that searches for methods with the [HelloWorld] attribute and generates an implementation:
Remark: If you are looking for a list of existing generators, take a look here: amis92/csharp-source-generators: A list of C# Source Generators (not necessarily awesome) and associated resources: articles, talks, demos. (github.com)