Click here to Skip to main content
Click here to Skip to main content

T4 – Too Troublesome to Tackle?

By , 18 May 2010
 

Text Template Transformation Toolkit (T4) is a code generator built into Visual Studio 2008 and 2010. Yes, you have it now on your machine :). It was proposed to me as a possible solution to the C# macros problem.

I played with it a little bit and my current verdict is it would be quite difficult to use in a serious project. Here’s why:

  1. No automated build integration

    This is a killer, especially if your templates include other templates. The only time template code is executed is when you save a template file. Not when you (re)build your solution. Not when you get your stuff from source control. If foobar.tt has changed and there are 50 files that include foobar.tt, you will have to hunt them down, open them in Visual Studio and save them to re-generate the code. That’s 51 files.

    This is not T4’s fault per se – all custom tools suffer from this problem, but it does not make the developer’s life any easier. There is some build integration in VS 2010, but “ in order to configure a Visual Studio project for build-time template transformation, you have to manually modify the MSBuild definition in the project file“. Not cool.

  2. No proper source control integration

    When you add your .tt file to source control, the generated file is added along with it, and every time you change anything, both files get checked out.

  3. No ability to group all files of a class under one node

    This is not a show stopper, but an inconvenience. I would like to have all code for class Foo to be under one node. Something like Foo.cs with Foo.props.tt below it, which generates Foo.props.cs. I am not sure how it can be accomplished with TT.

See also:

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0

About the Author

Ivan Krivyakov
Architect Sungard Consulting Services
United States United States
Member
Ivan is a hands-on software architect working for SunGard Consulting, in the New York City area. At present I am mostly building complex multi-threaded WPF application for the financial sector, but I am also interested in cloud computing, web development, mobile development, etc.
 
Please visit my web site: www.ikriv.com.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralDepends on your point of view...memberDave Elliott20 May '10 - 7:28 
I've been using it in a production environment for quite a while. While I agree that straight up T4 is cumbersome and doesn't produce exactly what I want; Oleg Toolkit is great at fixing those issues.
 
Point 1: I would agree, it would be nice if something was more readily available. We've decided that it will be the developers responsibilty to run it as necessary.
 
Point 2: I'm not sure what the issue is with this point. You should be allowed to check in which ever file you want. If a change is made, I would expect it to get checked out.
 
Point 3: This is taken care of by Oleg's toolkit. You can see this in action by getting the source code of an unrelated article that I wrote a couple of months back. In the article (http://www.codeproject.com/KB/library/EdmxParsing.aspx), I use T4 to generate lots of files in separate directories. By right clicking on the Driver.tt file and selecting "Run Custom Tool" all the files are created/updated all at the same time.
 
From my point of view, auto generation is great and I would rather use something than nothing. I also like the fact that T4 is baked into VS for use.
 
Cheers
GeneralRe: Depends on your point of view...memberIvan Krivyakov24 May '10 - 16:29 
The issue with point 2 is that normally we don't check in products of the compilation, such as binary files, etc. They are not part of the source and there is no point in storing them. They waste space, and checking them in and out all the time creates extra effort and noise in histories, etc.
 
It is good point about Oleg's toolkit. Too bad this feature is not built-in. This may seem like not a big deal for a single developer or a small shop, but this creates lots of legal and logistical issues for bigger corporations. You need to make sure the license is approved by the legal department, that all relevant developers have it installed, etc.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 18 May 2010
Article Copyright 2010 by Ivan Krivyakov
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid