Adding Your Own T4 Templates for EF4 to Visual Studio 2010

I’ve been missing the T4 template for POCO classes that shipped with CTP 1 of Entity Framework 4.0 but was absent from CTP 2.  So I wanted to create my own and have it available in Visual Studio when selecting “Add Code Generation Artifact” from the context menu after right-clicking on the design surface of an EDMX file.

I posted a question to the EF4 Forum and was pointed to a link stating that the template name has to start with the string “ADONETArtifactGenerator_”.  Armed with this information, I simply copied the installed template for self-tracking entities and replaced the .tt files with those of the POCO template from CTP 1.  The VS item template zip file is located here, along with a bat file that copies them to the appropriate directories and installs them into Visual Studio.  Enjoy.

About Tony Sneed

Married with three children.
This entry was posted in Technical. Bookmark the permalink.

5 Responses to Adding Your Own T4 Templates for EF4 to Visual Studio 2010

  1. Edwin G. says:

    This is what we were looking for. However, i don’t have the same VS2010 folder structure. The C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates folder is not there.
    Am I missing something? Thank you for your help.

  2. Tony says:

    Are you using VS 2010 Beta 2? What happens if you just create the item template directories yourself?

  3. Edwin G. says:

    Found it. We’re using 64-bit machines for our development and VS2010 is under C:\Program Files (x86). We created a 64-bit-compatible bat file, ran it and it worked. Thank you for the tip.

  4. rob says:

    Error 1 Compiling transformation: The type or namespace name ‘TemplateFileManager’ could not be found (are you missing a using directive or an assembly reference?)\Model1.Types.tt 15 1

  5. Shaleen says:

    Hi Rob

    Error 1 Compiling transformation: The type or namespace name ‘TemplateFileManager’ could not be found (are you missing a using directive or an assembly reference?)\Model1.Types.tt 15 1

    Try deleting the tt file and add a new one from VS2010, using self tracking entity and you get two tt files, one for teh context and one for the entities.Remove the file which you dont need and then compile and it will rebuild fine.

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