George J.'s profile“Daily Cycle”PhotosBlogLists Tools Help
    2/15/2009

    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_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Languages\File 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: ,

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks (3)

    The trackback URL for this entry is:
    http://gcapnias.spaces.live.com/blog/cns!1A746C4E01342B70!532.trak
    Weblogs that reference this entry