T4模板引用类文件怎么引用?

luhui1982 2016-05-25 10:15:18
比如App_Code 里面有个类 Test.cs 里面就是一些帮助类,连数据库之类的。我怎么在T4模板中引用?
我看到网上说可以引用dll的, 我不想把他编译成dll的, cs文件能引用么。
...全文
196 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sq-Zyz123 2016-05-25
  • 打赏
  • 举报
回复
这个还真不知道,我也是最近看到t4 模版研究了一下 也没太仔细研究。
luhui1982 2016-05-25
  • 打赏
  • 举报
回复
If this is a preprocessed template, there shouldn't be any problem. See Generating Text Files at Run Time by using Preprocessed Text Templates. If this is what you intended to do, check that the Custom Tools property of the file (when you view it in Solution Explorer) is TextTemplatingFilePreprocessor. You should be able to use <#@ import namespace="MyProject.Information.TableInfo" #> and use Table or TableInfo in the code. But if you want to use your Table class in a standard text template to generate code in your VS project (with Custom Tool set to TextTemplatingFileGenerator) then you need to compile the class in a separate VS project (or a separate solution) and import the DLL using the <#@assembly#> directive. Use the full absolute path to point to the DLL.

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧