Processor named ‘T4VSHost’ could not be found for the directive named ‘CleanupBehavior’

Posted on March 21, 2013. Filed under: Entity Framework, Visual Studio | Tags: , , , , , , |

There are two scenarios in which you may see the ‘Processor named ‘T4VSHost’ could not be found for the directive named ‘CleanupBehavior’’ error after installing Visual Studio 2012 Update 1.

  • Inside Visual Studio when code is being generated from an EF model – this isn’t supposed to happen and something probably went wrong during install.
  • When running EF code generation using TextTransform.exe – you need to let the T4 tool know about a new directive we added in Update 1.

 


What Changed?

In Visual Studio 2012 Update 1 we introduced some changes to the T4 processor (and our T4 templates) to allow virtual memory used during code generation to be freed back up by Visual Studio once code generation was complete. To enable this freeing of memory, we include a new CleanupBehavior directive in our T4 templates.

 


Resolving the Issue in Visual Studio

If you are seeing the “processor named ‘T4VSHost’ could not be found for the directive named ‘CleanupBehavior’” error from within Visual Studio then you have two options:

 

Option 1 – Remove the CleanupBehavior Directive

The simplest way to resolve the issue is just to remove the CleanupBehavior directive from the EF ttinclude files. VS will hold onto a little more virtual memory… but I doubt you will notice the difference.

  1. Browse to C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\
    (or whatever directory you installed Visual Studio in)
  2. Open each of the following files in notepad:
    • EF.Utility.CS.ttinclude
    • EF.Utility.VB.ttinclude
  3. Remove the following text from the first line of each file and save:
    <#@ CleanupBehavior Processor=”T4VSHost” CleanupAfterProcessingTemplate=”true” #>

 

Option 2 – Ensure Directive Processor is Registered

The second option is to ensure the directive processor is registered for Visual Studio.

  1. Make sure you have the following registry key:
    HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0_Config\TextTemplating\DirectiveProcessors\T4VSHost
  2. They key should have the following REG_SZ values:
    • Class: Microsoft.Data.Entity.Design.VisualStudio.Directives.FallbackT4VSHostProcessor
    • CodeBase: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Microsoft.Data.Entity.Design.dll
      (obviously you may need to update the CodeBase path depending on where you installed Visual Studio)

    RegKeys.png

 


Resolving the Issue for TextTransform.exe

TextTransform.exe is a tools that allows you to process T4 templates from the command line. When working in Visual Studio, the processor to handle the CleanupBehavior directive is automatically registered. However, when using TextTransform.exe it’s not and you will get the following message if you try to process your .tt file.

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF.Utility.CS.ttinclude(1,4) : error : A processor named 'T4VSHost' could not be found for the directive named 'CleanupBehavior'. The transformation will not be run.  The following Exception was thrown:
System.IO.FileNotFoundException: Failed to load directive processor T4VSHost.
at Microsoft.VisualStudio.TextTemplating.CommandLine.CommandLineHost.ResolveDirectiveProcessor(String processorName)
at Microsoft.VisualStudio.TextTemplating.Engine.ProcessCustomDirectives(ITextTemplatingEngineHost host, TemplateProcessingSession session, IEnumerable`1 directivesToBeProcessed)

Again, you have two options for resolving the issue.

 

Option 1 – Remove the CleanupBehavior Directive

The easiest way to resolve the issue is to follow the same steps listed under Option 1 in the previous section to remove the CleanupBehavior directive from the EF ttinclude files.

 

Option 2 – Register the Directive Processor with TextTransform.exe

You can use the –dp switch to register additional directive processors. Adding the following to your command will register the processor to deal with the new CleanupBehavior directive.

-dp T4VSHost!Microsoft.Data.Entity.Design.VisualStudio.Directives.FallbackT4VSHostProcessor!"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Microsoft.Data.Entity.Design.dll"

Here is a complete command sample:

> "C:\Program Files (x86)\Common Files\Microsoft Shared\TextTemplating\11.0\TextTransform.exe"
    -out MyModel.cs
    -I "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes"
    -a !!NamespaceHint!MyNamespace
    -dp T4VSHost!Microsoft.Data.Entity.Design.VisualStudio.Directives.FallbackT4VSHostProcessor!"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Microsoft.Data.Entity.Design.dll"
    MyModel.tt
About these ads

Make a Comment

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

3 Responses to “Processor named ‘T4VSHost’ could not be found for the directive named ‘CleanupBehavior’”

RSS Feed for RoMiller.com Comments RSS Feed

[…] If you are using Visual Studio 2012 Update 1 or later you also need to include an additional parameter to handle some changes we made to reduce the virtual memory usage during code g…: […]

Hi Miller,
I’m using Visual Studio 2012 update 2 with EF Power Tool Beta 3 installed. I try to use Reverse Engineer function to generate POCO classes but not luck, it gave me an error detail:
/* CodeTemplates\ReverseEngineerCodeFirst\Entity.tt(2,4) : error : Loading the include file ‘EF.Utility.CS.ttinclude’ returned a null or empty string. The transformation will not be run. */
I try to find EF.Utility.CS.ttinclude file but I don’t see “Entity Framework Tools” folder in the directory I installed VS2012, and I don’t see T4VSHOST in registry also. I don’t know how to fix this issue, because my scenario is so strange, and I can’t apply your solution to solve this. Hope you can help me with this, Thank you so much.

Thanks! First solution that you provided solved my problem. +1


Where's The Comment Form?

    About

    Rowan works as a Program Manager for the ADO.NET Entity Framework team at Microsoft. He speaks at technical conferences and blogs at romiller.com. Rowan lives in Seattle, Washington with his wife Athalie. Prior to moving to the US he resided in the small state of Tasmania in Australia. Outside of technology Rowan's passions include snowboarding, mountain biking, horse riding, rock climbing and pretty much anything else that involves being active. The primary focus of his life, however, is to follow Jesus.

    RSS

    Subscribe Via RSS

    • Subscribe with Bloglines
    • Add your feed to Newsburst from CNET News.com
    • Subscribe in Google Reader
    • Add to My Yahoo!
    • Subscribe in NewsGator Online
    • The latest comments to all posts in RSS

    Meta

Liked it here?
Why not try sites on the blogroll...

Follow

Get every new post delivered to your Inbox.

Join 166 other followers

%d bloggers like this: