0

我正在使用 T4 工具箱生成 cs 文件。但结果会生成正确的 C# 文件,但是......没有扩展名。什么问题?

<#@ template language="C#" hostspecific="true" debug="True" #>
<#@ output extension="txt" #>
<#@ include file="T4Toolbox.tt" #>
<#@ include file="$(ProjectDir)StoredProcedures.ttinclude" #>
<#@ include file="DB\SpGenerator.tt" #>
<#
/*
    <auto-generated>
    Do not change files!!
    </auto-generated>
*/
    var generator = new GeneratorSp();
    generator.tableName = ListOfTables();
    generator.Run();

#>



<#@ IntelliSenseLanguage processor="tangibleT4Editor" language="C#" #>
<#@ include file="SpTemplate.tt" #>
<#+ 
public class GeneratorSp : Generator
{
    public string[] tableName;
    protected override void RunCore()
    {
        var _template = new SpTemplate();
        foreach(var sp in tableName)
        {
            _template.SpName = sp;          
            _template.RenderToFile(sp); 
        }
    }
}
#>


<#@ IntelliSenseLanguage processor="tangibleT4Editor" language="C#" #>
<#@ Assembly Name="System.Core" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Data" #>
<#@ include file="DataAccess.ttinclude"  #>
<#@ include file="$(ProjectDir)ModelConnectionString.ttinclude"  #>
<#+
// <copyright file="SpTemplate.tt" company="">
//  Copyright © . All Rights Reserved.
// </copyright>

public class SpTemplate : Template
{
    public string SpName;
    public override string TransformText()
    {
        string CONN_STRING = ConnectionString();

        var data = new DataAccess(CONN_STRING);
        var sp   = SpName;
        var pars = data.ParametersDesc(sp);     
        string methodParameters = data.CreateParametersDesc(sp);
#>
namespace B2BSoft.Services.Data.Generated
{
    public  static partial class StoredProcedures
    {
        public static  <#= sp #>_Result <#= sp #>(<#= methodParameters #>)
        {
            return new <#= sp #>_Result();
        }
    }
}
<#+  
        return this.GenerationEnvironment.ToString();
    }
}
#>
4

1 回答 1

1

将文件名(包括其扩展名)传递给 Template.RenderToFile 方法:

_template.RenderToFile("FileName.sql");
于 2013-01-29T05:53:01.953 回答