views:

74

answers:

2

I have the following code in a tester class in my main assembly, PocoGenerator. This assembly is supposed to use a T4 template to generate POCO's based on L2S entities in a referenced assembly (a project reference), DataObjects.

var assemblyName = "DataObjects";
var dataObjects = AppDomain.CurrentDomain.Load(new AssemblyName(assemblyName));

Try as I may, I cannot get T4 to find the DataObjects assembly. I have tried various forms of assembly directives, like:

<#@ assembly name="DataObjects" #>
<#@ assembly name="DataObjects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" #>

to no avail. The code above works in the tester class, but not in the template. What am I doing wrong?

ADDED: I have resolved this issue by using the absolute path to the assembly in bot places I reference it, the directive as well as the class feature block, i.e.

<#@ assembly name="C:\Development\PocoGenerator\DataObjects\bin\Debug\DataObjects.dll" #>

and

var sourceAssembly = Assembly.LoadFile(@"C:\Development\PocoGenerator\DataObjects\bin\Debug\DataObjects.dll");

But I really don't like this, as I would like to use this template in various projects, and I just plain hate duplication, especially of magic strings.

A: 

I had a similar problem when I tried to include Less Css for .NET in my Web project.

I've ended up with copying the assembly in the root folder of my project and including it as a reference in the project itself. Then, I've added the following lines in the .tt file:

<#@ assembly name="dotless.Core.dll" #>

<#@ import namespace="dotless.Core" #>
<#@ import namespace="dotless.Core.configuration" #>

I'm sure that something similar should work with your assembly as well...

Regent
A: 

I've found there are a number of cases in creating and using the gax toolkit and packages where the build is perfectly happy with the way references are structured but the runtime gets all bothered because it can't find what it's looking for - this usually occurs when the main assembly references an assembly that uses gax elements and then that assembly in turn references another assembly that the main does not.

try directly including the assembly in question in your main assembly - and consider that you may need to write post build instructions to move it to an 'expected' location - while a nusiance, it should beat having to hardwire the path.

YMMV

Mark Mullin