T4: Text Template Transformation Toolkit

T4 is a template-based code generation engine supported in VS 2008 (and available for download for VS 2005). SubSonic 3.0 uses these files (.TT extension) in place of the old templating system. T4 can be used to generate C#, VB, XML, etc. T4 templates are pretty sweet.

Oleg Sych has a great post detailing just about everything you’d want to know about T4 templates. David Hayden provides a great screencast on using T4 templates which is a great way to see them in action. It has been a while since I watched the screencast, but if I recall he does a little DAL generation. I know there are tons of tools to do this, but if you are like me, a real-world example really helps me understand the usefulness of the latest and greatest technologies.

Simple T4 Example

<#@ Template Language="C#" #>
<# for (int i = 0; i < 10; i++) {
    Write("Hello World!");
} #>