在TextTemplate(t4)中使用自定义TYPE时出错 [英] Error while using custom TYPE in TextTemplate(t4)

查看:111
本文介绍了在TextTemplate(t4)中使用自定义TYPE时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了MVC项目,并在同一项目中添加了"Class1.cs"
第1类代码:

I created MVC project and added "Class1.cs" to it(in the same project)
Class1 code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcApplication2.Models;
namespace MvcApplication2
{
    public class EntityAttribute
    {
        public string Name { get; set; }
    }
    public class Entity
    {
        public List<EntityAttribute> Attributes { get; set; }
        public string Name { get; set; }
    }
    public class Class1
    {
        public static string getTable()
        {
            return "tbl";
        }
    }
}



我有文本模板文件.tt:



I have Text Template file .tt:

<#@ template debug="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="MvcApplication2.dll" #>
<#@ import namespace="MvcApplication2" #>
<#
    string s = Class1.getTable();
#>


当我在TextTemplate上运行CustomTool时,出现以下错误:
Error 2 Compiling transformation: Metadata file ''MvcApplication2.dll'' could not be found C:\Users\Igor\Documents\Visual Studio 2010\Projects\MvcApplication2\MvcApplication2\TextTemplate1.tt 1 1 MvcApplication2
当我更改<#@程序集名称="MvcApplication2.dll"#>时到完整路径<#@程序集名称="C:\ Users \ Igor \ Documents \ Visual Studio 2010 \ Projects \ MvcApplication2 \ MvcApplication2 \ bin \ MvcApplication2.dll"#>"

我收到以下错误:
Error 2 Compiling transformation: ''MvcApplication2.Class1'' does not contain a definition for ''getTable'' c:\Users\Igor\Documents\Visual Studio 2010\Projects\MvcApplication2\MvcApplication2\TextTemplate1.tt 8 20

我的错误在哪里?
谢谢您.


When I run CustomTool on TextTemplate I get the following error:
Error 2 Compiling transformation: Metadata file ''MvcApplication2.dll'' could not be found C:\Users\Igor\Documents\Visual Studio 2010\Projects\MvcApplication2\MvcApplication2\TextTemplate1.tt 1 1 MvcApplication2
When I change "<#@ assembly name="MvcApplication2.dll" #>" to full path "<#@ assembly name="C:\Users\Igor\Documents\Visual Studio 2010\Projects\MvcApplication2\MvcApplication2\bin\MvcApplication2.dll" #>"

I get the following error:
Error 2 Compiling transformation: ''MvcApplication2.Class1'' does not contain a definition for ''getTable'' c:\Users\Igor\Documents\Visual Studio 2010\Projects\MvcApplication2\MvcApplication2\TextTemplate1.tt 8 20

Where is my mistake??
Thank you

推荐答案

您必须先使用新方法编译程序集,然后才能执行模板,因为模板会随意链接.因此,它几乎不能与同一项目一起使用.

如果它不在同一个项目中,则请确保您引用的是它的最新版本,可能是您正在访问过期的本地副本或过期的GAC副本.当然,如果使用完整路径,则不是这种情况. [顺便说一句,使用
You need to compile the assembly with the new method before the template can be executed because it links the compiled assambly. So it will hardly work with the same project.

If it''s not in the same project, then make sure you are referencing the last build of it, may be you are accessing an out-dated local copy or an out-dated GAC copy. Of course this is not the case if you use the full path. [By the way, use


(SolutionDir),
(SolutionDir),


(ProjectDir)和
(ProjectDir) and


这篇关于在TextTemplate(t4)中使用自定义TYPE时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆