✅ Modern T4 Replacement for Design Time Codegen
Hey all!
I'm currently working on a library in which I was previously using a T4 template to generate many variants (varying on generic arity) of a struct type. I'm essentially at a point where I would like to rewrite the template for easier maintainability going forward (and to support multi-file output), and was wondering if there might a better option for design time codegen. Especially since T4 seems to be stuck on Framework and the syntax highlighting is very finicky.
One option I did some looking into was utilizing raw string literals and interpolation within a C# script file and running it via
dotnet-script
during a pre-build task, but alas, Rider is yet to add support for .csx files. So, without proper intellisense, diagnostics, and highlighting, it unfortunately doesn't give me a better workflow than I had using T4.5 Replies
@Zeth thanks! I'll take a look at CodegenCS in a bit. I might also try to see if I can override Rider's T4 engine implementation to use the dotnet tool.
GitHub
GitHub - scriban/scriban: A fast, powerful, safe and lightweight sc...
A fast, powerful, safe and lightweight scripting language and engine for .NET - scriban/scriban
Maybe $ig is an option.
If you want to make an incremental source generator, please make sure to read through both the design document and the cookbook before starting.
After looking into the various options discussed here, I believe that CodegenCS is best suited for the needs of my project. Thank you everyone :)