T4 Lessons Learned

Working with T4 recently I learned a couple of valuable lessons I’d like to share. Lesson 1: Template Language One of the parameters of the language directive is the language, which specifies the language used in the code blocks of the template. Two languages are specified, C# and VB.

However, any attempts to use…

Generate Output from T4 at Build Time

Text templates (aka T4) is a great feature in Visual Studio, that proves helpful in many scenarios. I use it for instance in developing Alchemy. However, it has a significant drawback: it does not generate code automatically when you build your solution. To build the files and generate their output you have to manually run…