Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

How many of you have ever used (or even know of) the Visual Studio Text Templating Engine?

I mean, T4 templates have been around for quite some years now. The where initially included in Visual Studio 2005 SDK, and they where moved to Visual Studio 2008 core just before releasing it.

What I want to know is if this is really used out there. I mean, why doesn't the VS team invested in a descent minimal editor for the templates? It doesn't even have syntax couloring! I know there are a couple of good T4 editors out there, but as they don't come built in, I tend to think that this is an unknown feature for most developers.

Have you ever used T4 templates in any of your projects? I'm really interested in answers that explain how they created their own T4 to accelerate, automate, or generate artifacts for your project.

share|improve this question
2  
Never heard of it... –  Lorenzo Oct 27 '10 at 19:34
3  
@Lorenzo: T4 is a code-generation system similar to CodeSmith, built into Visual Studio. It uses an ASP-like syntax to inject variable values into code templates. T4 is what gets invoked when you open the New View dialog in ASP.NET MVC. It is possible to create your own code-generation templates, but Microsoft hasn't made it very developer-friendly yet. –  Robert Harvey Oct 27 '10 at 20:22
    
Why did I first think of T4 Carrier lines? –  TheLQ Oct 28 '10 at 0:00
    
Don't make people Google (or ask what it is) - link the first reference to a suitable page. –  Peter Boughton Nov 19 '10 at 12:54
add comment

5 Answers

up vote 2 down vote accepted

I just started to use them recently with Entity Framework in order to generate the SQL scripts and/or POCO classes.

Before that, I'd used String Template for quick code generation. Deklarit's dkts were also a great solution, plus, it had a nice template editor right on Visual Studio (those were the days) :)

share|improve this answer
add comment

One of my peer groups migrated a lot of custom templates from Codesmith to T4. They like it pretty well, but they have a couple of people who have been modifying and creating custom templates for years so the lack of tools and polish does not affect them so much. In my team we still use Codesmith.

share|improve this answer
add comment

We use T4 in our project for several things:

  1. Auto-generating POCO classes in our DAL when our Entity Framework model is modified.
  2. Auto-generating SQL scripts for triggers when our Entity Framework model is modified.

So far they have been working great and have cut out a decent amount of dev time.

share|improve this answer
1  
EF is exploiding the use of T4 templates –  sebagomez Oct 28 '10 at 19:54
    
I'm not sure if you meant to type 'exploding' or 'exploiting' :) –  DaveK Oct 28 '10 at 20:35
add comment

A few years ago I was part of a couple of projects where we used T4 templates via the Guidance Automation Toolkit as well as the Smart Client Software Factory. On both projects we were able to take out most, if not all, of the repetitive setup steps for creating new modules that would work within the main Composite UI App Block shell applications we had created. The T4 templates we created would ask the developer/user for various pieces of project-specific data and then do everything from initial Visual Studio solution creation to view/controller creation. I agree with you that editing the templates isn't the easiest thing in the world, but the payoff was always worth it for us. There were some add-in's if I remember correctly that would add syntax coloring for you too...

share|improve this answer
add comment

I use the strong typed Page reference template from this article: http://blog.devarchive.net/2008/01/auto-generate-strong-typed-navigation.html

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.