【问题标题】:T4 trouble compiling transformationT4麻烦编译转换
【发布时间】:2010-05-19 13:06:09
【问题描述】:

我想不出来这个。为什么 T4 没有找到IEnumerable 类型?我正在使用 Visual Studio 2010。我只是希望有人知道为什么?

<#@ template debug="true" hostspecific="false" language="C#" #>
<#@ assembly name="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"  #>
<#@ import namespace="System" #>
<#@ import namespace="System.Data" #>
<#@ import namespace="System.Data.SqlClient" #>
<#@ output extension=".cs" #>
public static class Tables
{
    <#

    var q = @"
        SELECT 
            tbl.name 'table', 
            col.name 'column' 
        FROM 
            sys.tables tbl
        INNER JOIN 
            sys.columns col ON col.object_id = tbl.object_id
    ";

    // var source = Execute(q);

    #>
}
<#+
    static IEnumerable Execute(string cmdText)
    {
        using (var conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=t4build;Integrated Security=True;"))
        {
            conn.Open();

            var cmd = new SqlCommand(cmdText, conn);

            using (var reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                }
            }
        }
    }
#>

错误 2 编译转换:找不到类型或命名空间名称“IEnumerable”(是否缺少 using 指令或程序集引用?) c:\Projects\T4BuildApp\T4BuildApp\TextTemplate1.tt 26 9

【问题讨论】:

    标签: visual-studio-2010 t4


    【解决方案1】:

    我还建议参考 #assembly name="System.Core" 和 #import "System.Linq" 以便在使用 IEnumerable 时获得更多功能

    【讨论】:

    • 干杯 - 有一个类似的问题,我错过了一个程序集参考:D
    【解决方案2】:

    可能是因为 IEnumerable 在System.Collections

    【讨论】:

    • ....和约翰 - 你没有将 System.Collections 命名空间导入到你的模板中
    • 哦,我怎么没见过这个。谢谢!我一定已经失明了一个小时左右……
    猜你喜欢
    • 2013-02-09
    • 2011-04-15
    • 2015-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-04
    相关资源
    最近更新 更多