无法在T4模板中引用装配 [英] Can't reference an assembly in a T4 template
问题描述
我的主程序集PocoGenerator
中的测试器类中具有以下代码.该程序集应该使用T4模板来基于引用的程序集(项目参考)DataObjects
中的L2S实体生成POCO.
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));
尽我所能,我无法获得T4来查找DataObjects程序集.我已经尝试过各种形式的assembly
指令,例如:
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" #>
无济于事.上面的代码在tester类中起作用,但在模板中不起作用.我在做什么错了?
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" #>
和
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.
推荐答案
<#@ assembly name="$(ProjectDir)bin\Debug\ProofOfConcept.dll" #>
快乐编码!
这篇关于无法在T4模板中引用装配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!