Click here to Skip to main content
15,867,594 members
Articles / All Topics

T4 Template Goodness

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
2 Nov 2009CPOL1 min read 25.7K   10   2
T4 template goodness

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 Code Project.

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
How to create a simple T4 template
This article was originally posted at http://sachabarber.net?p=578

License

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


Written By
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 2016
  • Codeproject MVP 2016
  • Microsoft C# MVP 2015
  • Codeproject MVP 2015
  • 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 Pin
msdevtech27-Sep-13 3:04
msdevtech27-Sep-13 3:04 
GeneralIn-Process T4 Text Template Processing Pin
Member 85683398-May-12 5:41
Member 85683398-May-12 5:41 

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

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