Visual Studio Website Project: Add context menu for T4 files

Hey all,

I was excited to get going with SubSonic 3, but soon realized that website projects do not support T4 files (Text Template Transformation Toolkit).  I found that there is a command-line tool that you can use to generate the output, but I wanted something even easier.  So I set out to create a right-click context menu item to generate the code files.  This is one way for how you can do it.

  1. Add an external tool command to the command-line tool

    1. Click Tools -> External Tools…
    2. Click Add

      Title: Generate T4 Code
      Command: C:Program FilesCommon FilesMicrosoft SharedTextTemplating1.2TextTransform.exe
      Arguments: $(ItemFileName)$(ItemExt) -out $(ItemFileName).cs
      Initial Directory: $(ItemDir)

    3.  Check "Use Output Window" and click Ok
  2. Add it to the website project context menu
    1. Click View -> Toolbars -> Customize…
    2. Check Context Menus

    3.  With the Customize dialog still open, click the Tools menu
    4. While holding Ctrl, left click and drag your External Tool command to the Project and Solution Context Menus toolbar, which opens allowing you to continue dragging the external command it to Web Item

    5. Click the Project and Solution Context Menus toolbar, Click Web Item, and Right Click External Command
    6. Change the Name to Generate T4 Code and click enter

    7. Close the Customize dialog
  3. Now you have a right click context menu to generate code for .tt files

There is an annoyance with this method, however.  The context menu item will show up regardless of file type/extension.  If someone knows how to fix this, or has a better way of adding context menu items, I’m all ears.  I did find this article for how to add context menu items with VSIP, but that seemed a bit overkill…

One thought on “Visual Studio Website Project: Add context menu for T4 files

  1. RE: Visual Studio Website Project: Add context menu for T4 files

    As I mentioned in my previous post , I am playing around with SubSonic 3 . While the templates that come with it are a good starting point, I made some changes to make things feel a little more like the SubSonic I know and love… You can download my

Comments are closed.