Visual Studio T4 vs CodeSmith

Jake picture Jake · Mar 29, 2010 · Viewed 8k times · Source

I've been using CodeSmith for the past 2 years and love what it does for me. However, I also know about T4 which is built in to Visual Studio and can do some pretty cool stuff too. Based on conversations with friends T4 in VS2010 T4 is going to be even better.

So the question is: do I keep riding the CodeSmith bus or is it time to start converting all of my templates to T4?

Update Perhaps I wasnt clear in the way I asked the question. Obviously I'm not going to delete my cs templates and stop using them until I have the new templates working. However, is it even worth the effort at this point? Does T4 at this point offer a compleling advantage over CodeSmith? Is there some feature or set of features that by writing my templates for T4 instead I'll see a 100X improvement in my effeciency?

Answer

marc_s picture marc_s · Mar 29, 2010

I was very thrilled and excited about T4 and tried to convert all my CodeSmith stuff to T4 - only to learn there's quite a few things that are wrong with / lacking from T4.

  • no support for parameter for your template - you need to hard-code everything into your template.....
  • the Visual Studio host for T4 is rather limited
  • no direct and easy support for multiple output files from a single template

Check out Kathleen Dollard's What Wrong with T4 blog post - she's pretty much the Queen of Code Generation on .NET, and she sums it up very nicely - I totally agree 100% with her issues.

All in all, after a lot of playing around and trying, I have largely given up on T4 - it's just not yet ready for prime-time, at least not for the type of templates I was working with (mostly inspecting database tables to extract values, e.g. as foundation of a homemade ORM, or to extract constants and configuration settings etc. from the database)

And from experimeting with T4 in VS2010, I'm not sure how much of this has been fixed, really.... not a lot, it seems. There are a few other interesting concept (preprocessed templates, supposedly support for parameters etc.) but most of the basic flaws still seem to linger.....

So for now: don't throw out CodeSmith just yet!! Maybe T4 in VS2016 will be just as powerful.... but until then.....

Resources: