How To: Migrate T4 Text Templates from VS2008 to VS2010 Beta 2

At the .net open space in Leipzig I promised to write down the experience in migrating T4 Text Templates from VS2008 to VS2010 Beta 2. And here we go…

In order to migrate you will need to do the following

Issue1:  C# Version is now 4 by default


<#@ template language="C#v3.5" #>


<#@ template language="C#" #>

Issue2:  ModelingTextTransformation not any longer found


<#@ template inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation" #>

New: (You need an assembly reference eventually)

<#@ template inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation" #>
<#@ assembly name="C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.TextTemplating.Modeling.10.0.dll"#>


Issue: EnvDTE ProgID has changed from 9.0 to 10.0


<#@ assembly name=”envdte” #>
<# EnvDTE.DTE theDTE = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.
GetActiveObject("VisualStudio.DTE.9.0"); #>


Note it is always better to get EnvDTE from the Template host – this requires hostSpecific to be true

<#@ template hostSpecific="true" #>
<#@ assembly name=”envdte” #>

Now you can get the envdte this way

<#  IServiceProvider hostServiceProvider = (IServiceProvider)host;
var theDTE = (EnvDTE.DTE)hostServiceProvider.GetService(typeof(EnvDTE.DTE)); #>

Issue: Some other DSL DLL Names changed - here are new names

In GAC (do not use “.dll” in <#assembly#> reference)


Not in GAC (use. dll when referencing them)


You find them here

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\

or here

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\

or in the SDK Install Dir

I think these are the most common issues. I will add if i find more.

Happy generating


Comments (1)

  1. Gareth Jones says:

    Hey Tim – thanks for this – coupel of points

    Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll Microsoft.VisualStudio.TextTemplating.VSHost.10.0.dll

    These two should definitely be in the GAC – it’s a bug if they are not.

    You shouldn’t need the reference for the ModelingBaseClass if you are using any DSL directive processor as it should contribute the assembly reference.

Skip to main content