In T4 code generation, how can I grab a type from a referenced assembly?

吃可爱长大的小学妹 提交于 2019-12-05 15:09:56

I am guessing you want to access an assembly your building in your project. What I've done in the sample code below is adding a project to my solution called TestLib which I build to the folder .\T4Libs in the solution directory. TestLib has a class called MyHelper which holds a magic number.

FYI VS2010 SP1 added the great feature in that it no longer locks the imported assemblies so that's a good version to use.

<#@ assembly   name        = "$(SolutionDir)\T4Libs\TestLib.dll"  #>
<#@ import     namespace   = "TestLib"                            #>

<#
   var myHelper = new MyHelper ();
#>

// <#=myHelper.MagicNumber#>

Are you looking for the Assembly directive and/or are you looking for something in the System.Reflection.Assembly class (like LoadFile)?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!