Sunday, February 1, 2009

T4 Templates, T4 Toolbox, and VisualSVN

Hello, I spent some time messing with T4 this week. It seemed that T4 could be pretty powerful once you put in the considerable time and effort necessary to figure out how it works. Having said that It's not very intuitive. I guess that the basic template is pretty easy to do. It ends up looking like an old asp page, alot of the code that should be rendered then blocks of escaped code for some c# that can creates the dynamic info you need. This will then create a file as a subfile of your template every time the template is saved. So if your template is called MyStupidTempate.tt then when you save it you will see in solution explorer a plus sign next to the file. When expanded you will see MyStupidTempate.cs or .sql or .wtfe.
In short order you realize that you'll need T4 toolbox to do anything much more advanced than that. T4 Toolbox is an open source set of tools that allows you to do things such as create multiple output files for a template, use multiple templates to create the output and several other nifty things.
Here's the bitch. T4 Toolbox has an incompatability with VisualSVN. It's one or the other. In my office it's VisualSVN because it is an intragal part of our productivity. I did conciderable due dilligence on the subject and found that Kyle Baley had been down the same road before. I email Kyle and was informed that the issue hadn't been resolved, that is was on the T4 Toolbox side and in fact seems not to really even be acknowledged by the T4 Template guys. This, for the time being has landed T4 and it's nifty Toolbox in the crapper for me. I subsquently just wrote some C# code which did my codegen for me for this particular job and went on my merry way.
All told I have to say that my experience with CodeSmith in the past was much more fruitful. Pretty inutitve stuff and a very helpful IDE with intellisence and other perks. It's not free which is a drawback I guess but it's not very expensive either.
I don't do a whole lot of codegen so this isn't too big a deal for me but if I did or when I do I will definitly look back into CodeSmith and see if it has the capabilities I would need to integrate it into our application, build process, etc.