T4 templates and include files


It true that Microsoft provides no support for .tt template editing in Visual Studio 2008. They don’t plan to include this functionality in Visual Studio 2010 either – see feature request in Microsoft Connect. If Clarius Consulting hadn’t released their T4 Editor, there would be no support for editing T4 templates at all.

I have spend many hours lately in order to master T4 template creation. The most annoying thing about T4 templates, is that they work: TextTemplatingFileGenerator tool, the tool responsible transforming T4 templates to text artifacts, has no clue if a .tt file is a standalone template or an include template file. The tool transforms every file, without exception. When creating multi-file templates, this is really annoying – you get thousands of errors, which don’t really exist. When you are in the middle of template creation, this is really confusing.

How can you deal with this?

Actually there is only one solution: use .tt extension only for stand alone templates, or the starting template of multi-file template. Use an other extension, let’s say .ttinclude extension, for all other template files. TextTemplatingFileGenerator tool is not assigned as “Custom Tool” in the new extension, so transformation by default is disabled.

This looks nice, but .ttinclude extension, is not recognized as a known extension by Visual Studio or Clarius T4 Editor. You will get rid of the errors that are really annoying, but you loose all this nice functionality that Clarius T4 Editor provides. The good news is that you can deal with this, adding just two entries in your registry:


Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT.ttinclude]
@="VisualStudio.TextTemplating.1.2"

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftVisualStudio9.0LanguagesFile Extensions.ttinclude]
@="{4217b9d4-cd01-4b28-bc12-e289a19ecc6d}"

The first one, provides a type for .ttinclude extension, and a icon to recognize the files. The second one, makes sure that Clarius T4 editor, recognizes .ttinclude extension as a T4 template, and provides T4 template editing.

Happy transforming!

del.icio.us Tags: ,
Advertisements

George Capnias is working as Software Architect and Development Manager. His developing career started as soon as he left high-school and got a job as a programmer for a small software house in Athens. He started developing with Microsoft’s products as soon as Visual Basic for Windows came out. Since September '93, he was member in one of the greater BBS in Athens, where he served as a moderator for Windows related forums till '98. He started developing Web applications in '96. September '99 he started working as a trainer for Compact SA (Microsoft Gold Certified Partner for Learning Solutions - CPLS). He is certified as Microsoft Certified Professional & Site Building (MCP+SB), Microsoft Certified Solution Developer (MCSD) for Visual Studio 6 and Visual Studio 2003, Microsoft Certified Database Administrator (MCDBA) for SQL Server 2000, Microsoft Certified Technology Specialist (MCTS) for Windows & Web Applications, Microsoft Certified Professional Developer (MCPD) for Windows & Web Applications and he has the status of Microsoft Certified Trainer (MCT). He is the leader of dotNETZone.gr, an Athens, Greece, user group for Greek software developers using Microsoft’s .NET platform. He is delivering technical presentations and workshops for Microsoft Hellas to audiences like developers, ISVs. He was awarded as MVP for 'Visual Studio and Development Technologies' in '16 and '17, for 'ASP.NET/IIS technologies' in '06 and '15 and as MVP for 'VSTO technologies' in '07, '08, '09, '10, '11, '12, '13 and '14.

Posted in T4 Templates

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: