T4 Templates in ASP.NET MVC

Here’s a little known fact about T4 Templates…well besides that they exist in the first place. Visual Studio 2005 had support for T3 templates. T4 is the natural successor to T3. T3 is also the abbreviation used when marketing the movie Terminator 3: Rise of the Machines. I heard that the names are related, but I haven’t confirmed it beyond a doubt, which seems appropriate given the title of the movie. But you didn’t hear that from me, deal?

terminator3 Dude looks ready to write some code!

Although they’ve been around forever, I haven’t really dived into T4 templates until recently as I’ve been using them in Subtext. I’m excited that we’re now incorporating them into ASP.NET MVC.

The Visual Web Developer Team Blog just posted an in-depth look at T4 templates in ASP.NET MVC entitled, T4 Templates: A Quick-Start Guide for ASP.NET MVC Developers.

Be sure to check out their other post covering What’s New for MVC Tools in ASP.NET MVC 1.0 Release Candidate.

What others have said

Requesting Gravatar... Daniel Cazzulino Jan 31, 2009 8:28 PM
# re: T4 Templates in ASP.NET MVC
Wanna know the true story from one of the key actors? Wojtek holds the key ;)

blogs.msdn.com/.../414129.aspx

T3 came out after quite intensive research on template languages, including stringtemplate, nvelocity and others...
Requesting Gravatar... Thanigainathan S Jan 31, 2009 8:41 PM
# re: T4 Templates in ASP.NET MVC
Hi,

Please let me know th procedures to create our own templates.

Thanks & regards,
Thanigainathan.S
Requesting Gravatar... Mads Feb 01, 2009 3:31 AM
# re: T4 Templates in ASP.NET MVC
"Dude looks ready to write some code!"

Very funny :)
Requesting Gravatar... allan Feb 01, 2009 2:09 PM
# re: T4 Templates in ASP.NET MVC
@Thanigainathan, you can find what you need here: http://tinyurl.com/adhl43

;)
Requesting Gravatar... Xzibit Feb 01, 2009 6:34 PM
# re: T4 Templates in ASP.NET MVC
Yo dawg, I heard you like code, so we put some T4 in your code so it can generate code while you code.
Requesting Gravatar... Mike Feb 02, 2009 1:15 AM
# re: T4 Templates in ASP.NET MVC
"John Connor? It is time..."

When I first heard about T4 I was amazed. Though I don't see a way to use it in my project, I thinks it's great for frameworks and tools. I love how Subsonic uses T4 as well to generate data access classes, too smart!
Requesting Gravatar... gb Feb 02, 2009 1:57 AM
# re: T4 Templates in ASP.NET MVC
Trying to get to grasp on how I could increase productivity by using T4 templates to generate code.

Any example on how to use it in by invoking them from a windows form?

thanks
Requesting Gravatar... allan Feb 02, 2009 7:22 AM
# re: T4 Templates in ASP.NET MVC
@gb: t4 templates can be generated at the command line, so can be integrated into your CI build, or even mapped to a toolbar in the express versions of VS. msdn.microsoft.com/en-us/library/bb126245.aspx It should be found here: <root>\Program Files\Common Files\Microsoft Shared\Text Templating\1.1 As to productivity, the most common uses are for ORM and CRUD type forms, but they can be applied to anything repetitive. With any code generation tool you need to determine whether you will generate once and hand edit forever after, or regenerate whenever your model (or other 'source') changes, overwriting the generated code. MS tends to present the former pattern in Visual Studio with their project and page templates. Most ORM type solutions (including linq2sql) tend to follow the latter pattern. I personally would advise you to follow the latter as much as possible.

Hope that helps!
Requesting Gravatar... GB Feb 02, 2009 9:09 AM
# re: T4 Templates in ASP.NET MVC
@Allen:Thanks for your reply.I have built some in house code generator before linq came on the scene using CodeDom.That was hard work.
I generate entities,MVP etcc,I have a Gui where you can select table,Column etc... I would like to use T4 Template as they seem easy to maintain.But struggling to find even a noddy example that I can download where you generate anything from a windows form.
Thanks for your time
GB
Requesting Gravatar... Guo Jing Feb 03, 2009 11:53 PM
# re: T4 Templates in ASP.NET MVC
That's very good

What do you have to say?

(will show your gravatar)
Please add 8 and 4 and type the answer here: