Can I use T4 programmatically from C#?

Đorđe picture Đorđe · Oct 23, 2009 · Viewed 8.5k times · Source

I am writing software that produces C# code. Mostly I am using StringTemplate and StringBuilder.

Is there any way to use T4 templates direct from my code?

Answer

Dan Blanchard picture Dan Blanchard · Oct 23, 2009

Oleg Sych describes how to do this here: Understanding T4: Preprocessed Text Templates. Note that it looks like you'll need Visual Studio 2010 to generate a preprocessed Text Template, but you'll be able to host the preprocessed Text Template wherever you like - including within your WinForms application.