Choice of templating engine

The code generator is currently using the T4 templates from Microsoft as its templating engine.

The question is if we keep this templating engine for the re-write of the code generator, or we use a different templating engine.

If we keep T4, and as part of the move to .NET Core, we can then:

  • use the mono version of the T4 template engine (see if exists in .NET Core)
  • or write our own parser of T4 + code generator (not that hard of a task, since T4 is pretty straightforward)

If we want to change, we have to choose a new templating engine, and : migrate / rewrite all the templates that are written in T4 !

We can also make sure the templating engine is switchable, which would be the nicest design and allow any user of the code generator to chose their prefered templating engine. This seems the ideal thing to do, if we can do it on our short timeframe.

As templating engine are concerned, the open that comes to mind is StringTemplate. However I am not convinced about the performance, as I read several complaint about it. Performance is an issue for us, as the generation of a full Generative Objects application is involved hundreds of templates.

We should try the following 2, if we want to retain T4.


If stringtemplate has performance issues, then we need to test performance for similar workloads on the above ones as well.

This thread lists options - https://www.reddit.com/r/dotnet/comments/deun8e/is_there_a_valid_replacement_for_t4_templates/

But given existing investment in T4, I’d suggest we need a good reason to move to another templating engine, at least in the short term. My vote is to stick with T4 for now and pick the best of the two T4 for .Net Core options that Velu listed.

What’s the selection criteria: first one to work? performance? most recently maintained?

1 Like

Yes, short term is to use T4.

I am planning in the next weeks to try the various options. I have also seen written somewhere that T4 is already part of .NET Core ?

Yes, I read that somewhere as well, but the bulk of the search result evidence suggests otherwise.

I imagine you want pure .net core, but this might provide an interim: https://github.com/RdJNL/TextTemplatingCore

This suggest that T5 might be the go:
https://notquitepure.info/2018/12/12/T4-Templates-at-Build-Time-With-Dotnet-Core/
and there is a comment in that article that talks about dotnet CLI t4, which lead me here:

https://www.nuget.org/packages/dotnet-t4/

1 Like

Thank you @garth, I will check all this !