views:

645

answers:

2

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?

A: 

Do both ... ride the codesmith bus while you convert all of your templates to t4 (or at least any new projects). That mitigates risk for you and your company ;-)

Joel Martinez
Sorry Joel, but your answer besides being obvious it doesnt really help. I'm looking at the next year or so. The templates I've created are fairly extensive so it will be a lot of work moving over. work that I don't get paid for. just like any other business, I'm not going to invest in something just b/c its cool. So perhaps I need to change my question a bit to be clearer.
Jake
+10  A: 

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:

marc_s
Thanks. This is more along the lines of what I was looking for. As an example, I have a template that that generates partials for all of the classes in my Entity Framework edmx file. So being able to pass parameters between templates is a must. Being able to generate more that 1 file from 1 template would also be really nice.
Jake
@Jake: if you have your stuff in VS already (like in your EDMX file), you can do lots of cool things with T4, since it can easily parse the XML that makes up the EDMX. Also, with Oleg Sych' T4Toolbox, you can output more than 1 file from a template - it's just nowhere near as easy as it should be.....
marc_s
@marc_s: T4 is just .NET and you can do pretty much anything in T4 that you can do in .NET. It does not really have these constraints you complain about, it's just maybe not as easy as you want it to be. Codesmith is hopefully better than T4 or they will be out of business.
Michael Maddox