VS2010 下T4引用程序集,未能找到元数据文件(xxx.dll could not be found)

VS2010 下 T4使用
<#@ assembly name="System.Data.SQLite.dll" #>
可以能出现下述错误
Error    3    Compiling transformation: 未能找到元数据文件“System.Data.SQLite.dll”   
问题原因:
http://blogs.msdn.com/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.

为了避免因为项目与模板在.net framework 版本不一致上引发程序集错误,T4 的程序集已经完全独立于所在项目的程序集。项目的程序集不再直接影响模板的程序集。

这里提供了5种解决方案
http://weblogs.asp.net/lhunt/archive/2010/05/04/t4-template-error-assembly-directive-cannot-locate-referenced-assembly-in-visual-studio-2010-project.aspx

  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.

    注如:D:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies,拷进去之后需要重启vs2010.

  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.
posted @ 2010-10-27 09:00  life++  阅读(7463)  评论(0编辑  收藏  举报