Can't reference an assembly in a T4 template

前端 未结 4 2042
孤独总比滥情好
孤独总比滥情好 2020-12-05 02:48

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

相关标签:
4条回答
  • 2020-12-05 02:52

    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...

    0 讨论(0)
  • 2020-12-05 03:11
    <#@ assembly name="$(ProjectDir)bin\Debug\ProofOfConcept.dll" #>
    

    Happy Coding!

    0 讨论(0)
  • 2020-12-05 03:14

    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

    0 讨论(0)
  • 2020-12-05 03:15

    To reference assembly in T4 template in VS2010 you have some options:

    1. GAC your assemblies and use Namespace Reference or Fully Qualified Type Name
    2. Use a hard-coded Fully Qualified UNC path
    3. Copy assembly to Visual Studio "Public Assemblies Folder" and use Namespace Reference or Fully Qualified Type Name.
    4. Use or Define a Windows Environment Variable to build a Fully Qualified UNC path.
    5. Use a Visual Studio Macro to build a Fully Qualified UNC path.

    I would suggest that you put a referenced assembly in your Public Assemblies Folder, another, maybe even better solution would be to hard code the path of your referenced assemblies.

    Very nice post on this topic: T4 Template error - Assembly Directive cannot locate referenced assembly in Visual Studio 2010 project.

    Basically MS decided to the the braking change, that the project referenced assemblies are not referenced by T4 engine, too.

    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.

    More on that: What's new in T4 in Visual Studio 2010

    0 讨论(0)
提交回复
热议问题