T4 模板在某些 PC 上生成额外的新行 [英] T4 Template is Generating Extra New Lines on Some PCs

查看:15
本文介绍了T4 模板在某些 PC 上生成额外的新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在实体框架中使用 T4 类时,有几个开发人员生成的类为每一行生成一个额外的新行.我想知道这是否是某种需要更改的设置,以便他们的 T4 生成文件看起来像其他开发人员生成的文件.作为我正在谈论的示例:(删除了特定名称,但您应该能够看到从同一 *.tt 文件生成的新行数的差异.)

While using T4 classes for entity framework there are a couple of developers who generate classes with one extra new line for every line generated. I'm wondering if this is some kind of setting that needs to be changed so that their T4 generated files look like the generated files form other developers. As an example of what I am talking about: (removed specific names but you should be able to see the difference in the number of new lines generated from the same *.tt file.)

(更新:该问题也出现在其他 T4 模板中,而不仅仅是 EF.两台 PC 都使用 TextTemplatingFileGenerator 作为 T4 自定义工具.)

(Update: The issue occurs in other T4 Templates as well, not just EF. Both PCs are using TextTemplatingFileGenerator as the T4 custom tool.)

我电脑的 T4 输出:

T4 output from my PC:

    public virtual DbSet<GeneratedObject1> GeneratedObject1 { get; set; }
    public virtual DbSet<GeneratedObject2> GeneratedObject2 { get; set; }

    public virtual int SomeMethod1(Nullable<int> inParameter)
    {
        var localParameter = inParameter.HasValue ?
            new ObjectParameter("SomePropertyName", inParameter) :
            new ObjectParameter("SomePropertyName", typeof(int));

        return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("SomeMethod1", localParameter);
    }

    public virtual int SomeMethod2(Nullable<int> inParameter)
    {
        var localParameter = inParameter.HasValue ?
            new ObjectParameter("SomePropertyName", inParameter) :
            new ObjectParameter("SomePropertyName", typeof(int));

        return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("SomeMethod2", localParameter);
    }

来自他们 PC 的 T4 输出:

T4 output from their PC:

public virtual DbSet<GeneratedObject1> GeneratedObject1 { get; set; }

public virtual DbSet<GeneratedObject2> GeneratedObject2 { get; set; }


public virtual int SomeMethod1(Nullable<int> inParameter)
{

    var localParameter = inParameter.HasValue ?
        new ObjectParameter("SomePropertyName", inParameter) :
        new ObjectParameter("SomePropertyName", typeof(int));


    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("SomeMethod1", localParameter);
}


public virtual int SomeMethod2(Nullable<int> inParameter)
{

    var localParameter = inParameter.HasValue ?
        new ObjectParameter("SomePropertyName", inParameter) :
        new ObjectParameter("SomePropertyName", typeof(int));


    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("SomeMethod2", localParameter);
}

(文件中的文本大致相同.)我的文件:

(Of roughly the same text in the file.) My file:

他们的文件:

推荐答案

What @ralf.w.正在解决这个问题.问题计算机上 .tt 文件中的行尾是 LF,这会导致在转换工具运行时生成额外的行尾.正确的行尾应该是 CR LF.一旦我们更改了 .tt 文件中的行尾,就可以正确生成输出文件.我还将 Git 中的行结束设置更改为按原样结帐,按原样提交.这个问题有一些关于行尾设置的含义以及它们可以在哪里设置的信息被改变.

What @ralf.w. was getting at was the solution to this problem. The line endings in the .tt files on the problem computer were LF and this causes extra line endings to be generated when the transformation tool runs. The correct line endings should be CR LF. Once we changed the line endings in the .tt files, the output files were generated properly. I also changed the line ending settings in Git to checkout as-is, commit as-is. This question has some information on what the line ending settings mean and where they can be changed.

Notepad++ 用于将问题 .tt 文件转换为 CR LF(我们没有那么多.)转到 EditEOL ConversionWindows (CR LF)

Notepad++ was used to convert the problem .tt files to CR LF (we didn't have that many.) Go to EditEOL ConversionWindows (CR LF)

这篇关于T4 模板在某些 PC 上生成额外的新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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