zwei1121

博客园 首页 新随笔 联系 订阅 管理

In a T4 template the executing assembly is not yours but one from the T4 engine.

To access types from your assemblies, you have to perform the following steps:

  1. Add a reference to your assembly to the template. Put that at the top of it:

    <#@ assembly name="$(SolutionDir)<Project>\bin\Debug\<Project>.dll" #>
    
  2. Import the namespace of your assembly. Put that somewhere below the previous line:

    <#@ import namespace="<Project>.<Namespace>" #>
    
  3. To access the types in this assembly, pick one of them and get the assembly from it:

    var assembly = typeof(<Type in assembly>).Assembly;
    var types = assembly.GetTypes()
                        .Where(t => String.Equals(
                            t.Namespace,
                            "RepoLib.Rts.Web.Plugins.Profiler.Models",
                            StringComparison.Ordinal))
                        .ToArray();
posted on 2014-11-27 14:23  zwei  阅读(217)  评论(0编辑  收藏  举报