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

T4 Template Goodness

By , 2 Nov 2009
Rate this:
Please Sign up or sign in to vote.

I must admit I kinda missed the boat with T4 templates and what was capable of them, which annoys me, so I set out to try and have a look at them the other day, but low and behold Karl Shifflett has beaten me too it.

Karl has an excellent blog post http://karlshifflett.wordpress.com/2009/10/30/t4-preprocessed-text-templates-in-visual-studio-2010/ which talks about the new partial class support available for T4 templates in VS2010.

In case you have totally missed the boat, T4 templates are a text template that when saved will run some code. Now this code can do all sorts of things as demonstrated so beautifully by Daniel Vaughan in his excellent T4 EnvDTE article over at codeproject

http://www.codeproject.com/KB/codegen/T4Metadata.aspx

Daniel basically shows how to use T4 to create type safe metadata to get rid of magic strings (which we all hate).

Ok so getting back to T4 basics, T4 uses some classic ASP type syntax and you can embed c# code between special characters. Again see Karl for an example of this.

One thing is for sure T4 looks to be getting a whole lot better in VS2010. can’t wait.

Oh and here are some other good T4 resources:

T4: Text Template Transformation Toolkit

http://www.olegsych.com/2007/12/text-template-transformation-toolkit/

How to create a simple T4 template

http://www.olegsych.com/2007/12/how-to-create-a-simple-t4-template/

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Sacha Barber
Software Developer (Senior)
United Kingdom United Kingdom
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)
 
- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence
 
Both of these at Sussex University UK.
 
Award(s)

I am lucky enough to have won a few awards for Zany Crazy code articles over the years

  • Microsoft C# MVP 2014
  • Codeproject MVP 2014
  • Microsoft C# MVP 2013
  • Codeproject MVP 2013
  • Microsoft C# MVP 2012
  • Codeproject MVP 2012
  • Microsoft C# MVP 2011
  • Codeproject MVP 2011
  • Microsoft C# MVP 2010
  • Codeproject MVP 2010
  • Microsoft C# MVP 2009
  • Codeproject MVP 2009
  • Microsoft C# MVP 2008
  • Codeproject MVP 2008
  • And numerous codeproject awards which you can see over at my blog

Comments and Discussions

 
Question[My vote of 1] Nothing new Pinmembermsdevtech27-Sep-13 3:04 
GeneralIn-Process T4 Text Template Processing PinmemberMember 85683398-May-12 5:41 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 2 Nov 2009
Article Copyright 2009 by Sacha Barber
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid