Use class inside a T4 template

拜拜、爱过 提交于 2019-12-01 15:58:47
GarethJ

In general, if you need to actually use the Container class's functionality in your template, you'll want to load the assembly that your project is building. This does introduce a circular dependency, as you need a built version of your assembly in order to regenerate code that is going to be included in that assembly, so be aware of that.

If you're using VS2010 or above, you'll be able to use something like:

<#@ assembly name="$(TargetPath)" #>
<#@ import namespace="Your.Namespace" #>

and then use your Container class.

If you have VS2010SP1 or above, this will cause you no probelms with locking that assembly in memory, but if you're earlier than that, then you'll have to restart Visual Studio after each generation before you can rebuild your project.

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