本文介绍了在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时,出现以下错误:
Error2Compiling transformation: Metadata file ''MvcApplication2.dll'' could not be foundC:\Users\Igor\Documents\Visual Studio 2010\Projects\MvcApplication2\MvcApplication2\TextTemplate1.tt11MvcApplication2
当我更改<#@程序集名称="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:
Error2Compiling transformation: Metadata file ''MvcApplication2.dll'' could not be foundC:\Users\Igor\Documents\Visual Studio 2010\Projects\MvcApplication2\MvcApplication2\TextTemplate1.tt11MvcApplication2
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

推荐答案




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

10-11 16:04