T4 Template is Generating Extra New Lines on Some PCs

半世苍凉 提交于 2019-12-04 15:37:29

问题


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.)

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

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

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

Edit:

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

Their file:


回答1:


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++ was used to convert the problem .tt files to CR LF (we didn't have that many.) Go to EditEOL ConversionWindows (CR LF)



来源:https://stackoverflow.com/questions/39474911/t4-template-is-generating-extra-new-lines-on-some-pcs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!