T4 Template is Generating Extra New Lines on Some PCs
Asked Answered
L

1

28

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: My file

Their file: Their file

Liva answered 13/9, 2016 at 16:30 Comment(10)
Are they on the exact same version of Visual Studio as well as Entity Framework version?Illuminative
Yes, VS 2015 (occurred while we were using 2013 as well) and the Entity Framework version is part of the project and in the repo so it should be the same for both of us.Liva
Can you open the file in a hex editor and post a screenshot? I would be curious to see what the raw content of the file is with regard to carriage returns, line feeds, unprintable chars, etc.Toitoiboid
Updated, but I'm not really seeing anything that sticks out.Liva
@Liva I had sometime problem with line-endings getting back from git. So I can see nothing from your generating tt files here? (there are 0D 0A compared to 0D 0A 0D 0A in your output)Mellifluous
I don't think the problem is git. The files are generated with the extra new lines on their machine. The problem is there before they have been updated in git.Liva
Having the same issue in our team, how was this resolved for you?Latashialatch
@Latashialatch The issue has not been resolved yet. I've updated the question with a little more information.Liva
I'd check the various users' preferences in Visual Studio related to whitespace. I do not have VS on my PC at the moment otherwise I'd try and help narrow down which setting, but as I recall there may be some settings for T4 templates, and I know there are settings on whitespace (spaces vs tabs, etc.)Agronomics
I check in the "Text Templating" section of the settings and there is only one setting which is for showing a security message. I also did a search in the settings and couldn't find anything else that might be related to .tt files. I ran TextTemplating.exe from the command line on a .tt file and got the same problem; so the issue does not seem to be related to Visual Studio.Liva
L
34

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)

Liva answered 24/2, 2017 at 15:18 Comment(1)
Thanks Thomas - saved my wasting even more time. For those searching as I did I ran into this problem using EF.Reverse.POCO.GeneratorRetentivity

© 2022 - 2024 — McMap. All rights reserved.