Is anyone using the built-in code generation provided via text templates (using .tt files)? If so what are the main pro's/con's over other solutions like codesmith?
the T4 generation was pretty woeful in 2005. Apparently it's OK in 2008, but we went with Codesmith, as this was before 2005.
I assume that you will have seen the T4 editor? There's a free edition from Clarius. Also, there's a great wealth of information here in Oleg's blog.
My understanding is that you could get T4 to work and that it's fit for purpose, but that CodeSmith is a bit more mature.
I would say before you use T4 look at your other options:
- CodeSmith
- XML/XSLT
- CodeDom
- other apps like CodeSmith
One thing that I do like is T4 is built into the compile process for free.
I second what Travis says about Oleg / Clarius.
You might also want to read this site as a resource:
Kathleen Dollard at gendotnet
Her book: Code Generation in Microsoft .NET
If I remember correctly this mostly touches on XML/XSLT and CodeDom but might give you some ideas / contrast
A page of T4 resources from Hanselman:
T4 (Text Template Transformation Toolkit) Code Generation - Best Kept Visual Studio Secret
Extra: Kathleen Dollard on DotNetRocks
I would say I have used T4 for some Code Generation but about the time I got the hang of it, I had moved towards using some Open Source frameworks to remove the need to write tedious code.
T4 templates are used as the primary code generation technique used by the Service Factory. Of course, they are also used by the DSL Tooklkit which is part of the Visual Studio SDK.
I've had very few problems with them, and the Clarius T4 Editor makes them even more productive. The DSL toolkit (and thus the Service Factory) allow the template to iterate over a model to produce code. Other directive processors allow a template to process any other sort of data (XML documents or schemas, database schemas or data).