Sunday, January 23, 2011

Referencing Assemblies: T4 Gotcha

When I run T4 Templates through Visual Studio 2008, I don't have to give the full path to reference GAC assemblies:

<#@ assembly name="System.Data.dll" #>

But when I run the template in my own executable using Microsoft.VisualStudio.TextTemplating.Engine, I have problems.

If the Template code is in VB.NET, I get:

vbc : Command line (0,0) : error BC2006: Compiling transformation: option 'r' requires ': <file_list>'

If the Template code is in C#, I get:

c:\Users\jacks\AppData\Local\Temp\rnftuopt.0.cs(3,18) : error CS0234: Compiling transformation: The type or namespace name 'Data' does not exist in the namespace 'System' (are you missing an assembly reference?)

To fix this, I referenced the full path of the assembly.

<#@ assembly name="C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll" #>

NOTE: This doesn't seam to apply to non-GAC assemblies; I have noticed that I don't have give the full path of my own assemblies as long as they are in the same folder as my executable.

No comments: