T4 模板在某些 PC 上生成额外的新行

T4 Template is Generating Extra New Lines on Some PCs

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

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

我电脑的 T4 输出:

    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 输出:

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);
}

编辑:

(文件中大致相同的文本。) 我的档案:

他们的档案:

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

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