17

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?

Dariusz Woźniak
  • 8,073
  • 5
  • 48
  • 67
Jake
  • 878
  • 9
  • 22
  • answer to your update: No, T4 has no compelling advantages over CodeSmith, other than being included in VS2008 and up, and thus being "free" to VS users. – marc_s Mar 29 '10 at 18:38

1 Answers1

24

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
  • 675,133
  • 158
  • 1,253
  • 1,388
  • 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 Mar 29 '10 at 14:57
  • @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 Mar 29 '10 at 15:02
  • 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 Mar 29 '10 at 15:49
  • "only to learn there's quite a few things that are wrong with / lacking from T4." - do you still have the same feeling about T4? What if I need some templates, code snippets and certain task automation on a project that I am inheriting - which one should I choose? Any advice, thanks. – VoodooChild May 25 '11 at 17:51
  • 3
    5 years behind. What is new in the battle CodeSmith vs T4? – Evgeni Nabokov Feb 05 '15 at 10:18
  • @EvgeniNabokov we're still reliant on third-party solutions for any kind of "IDE experience", even syntax highlighting doesn't come with Visual Studio. – user247702 Jan 25 '16 at 16:49
  • I have come back to this (having used codesmith in the past, currently using T4 and now looking at asp.net 5 and related libraries that have limited support with T4) I have seen this: http://www.bricelam.net/2015/03/12/t4-on-aspnet5.html (but not used it yet) and feel there is a gap for a good templating tool, preferably dnx/cross platform) – Mark Redman Feb 01 '16 at 10:59