加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – T4模板装配指令

发布时间:2020-12-15 04:00:37 所属栏目:百科 来源:网络整理
导读:我有一个定制的dll,它有一个类,并且(为了简单起见)有一个方法,它将返回一个字符串. 我有一个项目,引用了dll,我想在该项目中使用一个(不是预处理的)T4模板,这个模板称之为方法.我试过这个: #@ template debug="true" hostspecific="false" language="C#" ##@
我有一个定制的dll,它有一个类,并且(为了简单起见)有一个方法,它将返回一个字符串.

我有一个项目,引用了dll,我想在该项目中使用一个(不是预处理的)T4模板,这个模板称之为方法.我试过这个:

<#@ template debug="true" hostspecific="false" language="C#" #>
<#@ assembly name="MyDLL.dll" #>
<#@ output extension=".cs" #>
<#
    var template = new MyDLL.MyNamespace.MyClass();
        this.Write(template.Run());
#>

我收到以下错误:

Error 14 Compiling transformation: Metadata file ‘MyDLL.dll’ could not be found
Error 13 A namespace cannot directly contain members such as fields or methods

即使MyClass.Run()只是一个返回“// hello”;

解决方法

好像你的问题:

Error Compiling transformation: Metadata file ‘dotless.Core’ could not be found

这是因为这里描述的兼容性破坏:

http://weblogs.asp.net/lhunt/archive/2010/05/04/t4-template-error-assembly-directive-cannot-locate-referenced-assembly-in-visual-studio-2010-project.aspx

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读