Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing an assembly in a T4 template

It's been a while since I last used T4 and this is probably a silly question...

Is it possible to reference an arbitrary assembly from a template?

Example:

  • I have a class that I'd like to use in Project X
  • Project X.Test references X and contains the .tt file

I assume the following should work

<#@ assembly name="X" #>

But I get the following error on save:

Compiling transformation: Metadata file 'X' could not be found

What am I doing wrong?

(In case anyone's interested: I'm trying to automatically generate a particular type of tests based on some metadata that I get from X)

Update: it looks like VS2010 has broken the assembly resolution behavior that I was expecting. From http://blogs.msdn.com/b/garethj/archive/2010/04/15/what-s-new-in-t4-in-visual-studio-2010.aspx:

T4's assembly set is completely separated from the containing project's assembly set to avoid picking up the wrong assemblies when a project targets previous framework versions. Project assemblies are no longer used to resolve template assembly directives.

Are there any workarounds, besides using absolute paths?

like image 906
Diego Mijelshon Avatar asked Jul 13 '10 21:07

Diego Mijelshon


1 Answers

You can use VS macro variables such as $(SolutionDir) in your reference as of VS2010 e.g.

<#@ assembly name="$(SolutionDir)\Project1\bin\debug\Foo.dll" #>
like image 64
GarethJ Avatar answered Sep 18 '22 12:09

GarethJ