T4 code generation: access types in current project

后端 未结 1 1484
南笙
南笙 2021-01-04 02:28

Using T4 code generation, is it possible to access the types defined in the current project?

For example, if I have an interface and I want to delegate its implement

相关标签:
1条回答
  • 2021-01-04 02:38

    While this doesnt solve the locking problems (although ive heard that VS2010 does), you could try copy the dll to a temp location and just use that copied assembly..

    <#@ template debug="false" hostspecific="false" language="C#" #>
    <#@ output extension=".txt" #>
    <#@ import namespace="System.Reflection" #>
    <#@ import namespace="System.IO" #>
    <#    
    var newFileName = System.IO.Path.GetTempFileName();
    System.IO.File.Copy(@"C:\Development\CustomAssembly.dll",newFileName,true);
    
    var assembly = Assembly.LoadFrom(newFileName);
    var type = assembly.GetType("CustomAssembly.DummyClass");   
    #>
    <#=newFileName#>
    <#=type#>
    
    0 讨论(0)
提交回复
热议问题