Blank lines

May 27, 2014 at 3:22 AM
Sometimes generated files have extra blank lines, Sometimes they do not. This depends on the computer. We've tried to launch VS in safe mode without effect.

This result in commits with a lot of blank lines shuffling.

Any advise on why this could be happening? What could we look at to fix this?
Coordinator
May 27, 2014 at 5:49 AM
I don't think this has come up before. When you say 'extra blank lines', do you mean at the end of the file, or between all lines? Also, can you check exactly what characters you get? e.g. is it two sets of CR LF?
May 27, 2014 at 2:45 PM
Before forget, all on VS2013. From what I'm seeing it's CR+LF in both cases, just in 1st example below there're extra CR+LF.
I suspected perhaps VS reformats the code after it's generated, but I'm not sure why it would. And as I said, tried launching in safe mode to ensure no extension influences.

It seems most computers want to generate blank lines. I haven't been able to pinpoint though why one would want to generate them, and the other wouldn't.

Example of format with extra blank lines as it was generated:
        partial void SupplierImportOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, System.Web.HttpPostedFileBase sourceFile);

        public override System.Web.Mvc.ActionResult SupplierImport(System.Web.HttpPostedFileBase sourceFile)
        {
            var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.SupplierImport);


            ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "sourceFile", sourceFile);


            SupplierImportOverride(callInfo, sourceFile);

            return callInfo;

        }


        partial void InvokeDefaultActionOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, System.Web.HttpContextBase httpContext);

        public override System.Web.Mvc.ActionResult InvokeDefaultAction(System.Web.HttpContextBase httpContext)
        {
            var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.InvokeDefaultAction);


            ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "httpContext", httpContext);


            InvokeDefaultActionOverride(callInfo, httpContext);

            return callInfo;

        }
Example of the generation result on a different computer:
        partial void SupplierImportOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, System.Web.HttpPostedFileBase sourceFile);

        public override System.Web.Mvc.ActionResult SupplierImport(System.Web.HttpPostedFileBase sourceFile)
        {
            var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.SupplierImport);
            ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "sourceFile", sourceFile);
            SupplierImportOverride(callInfo, sourceFile);
            return callInfo;
        }

        partial void InvokeDefaultActionOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, System.Web.HttpContextBase httpContext);

        public override System.Web.Mvc.ActionResult InvokeDefaultAction(System.Web.HttpContextBase httpContext)
        {
            var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.InvokeDefaultAction);
            ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "httpContext", httpContext);
            InvokeDefaultActionOverride(callInfo, httpContext);
            return callInfo;
        }
Coordinator
May 27, 2014 at 6:05 PM
On machines where it happens, does it happen for all generated files? e.g. do you see that in T4MVC.cs, and all the other .generated.cs?

Another test would be to write a trivial .tt file (no T4MVC) that generates simple code, to see if you see this as well.
May 27, 2014 at 6:26 PM
Yes, happens in all files, including T4MVC.cs. But now that I looked at it it seems sometimes there're more blank lines, sometimes less, and sometimes everything is finely formatted.

I'm very unfamiliar with .tt, but if you could provide simple .tt file for testing I'll be happy to run on different machines to test it.
Coordinator
May 27, 2014 at 7:15 PM
Try simply adding a new 'Text Template' (not 'Runtime Text Template'!) into your solution, and just put the following into it:
<#@ template language="C#" debug="true" hostspecific="true" #>

class Hello
{
}
Then look at the .cs file that gets generated under it and check if it has extra blank lines. It's very strange that you get such randomness. I would expect it to be very predictable.
May 27, 2014 at 7:47 PM
That just results in

class Hello
{
}
Tried it on both computers where we get blank lines and we don't, and result is the same.
Coordinator
May 27, 2014 at 8:10 PM
I'm not sure what in t4mvc.tt might cause this. One thing you can try doing is isolate the source of the issue in t4mvc. e.g. by starting with it empty and adding pieces one by one till you find the trigger.

I'd try that but I can't get a repro. I tried 'Run Custom Tool' on it 10 times in a row, and the generated files never changed.
May 28, 2014 at 12:06 AM
Which one do you get? Which one is expected? With extra blank lines? Or without them?
May 28, 2014 at 12:16 AM
Also, if I try to debug it, can I somehow see the intermediate result? Perhaps I'll be able to see when the extra lines are inserted? Again, depends on whether in general lines should be there as result of transformation. Or not...
Coordinator
May 28, 2014 at 1:10 AM
It's expected not to have extra lines. e.g. see this file.
May 28, 2014 at 2:37 PM
One thing I noticed is that in t4mvc.cs when there're a lot of blank lines, there're blank lines before comments, from line 1 to line 22. Is that of any help to see what's going on?






















// <auto-generated />
// This file was generated by a T4 template.
// Don't change it directly as your change would get overwritten.  Instead, make changes
Coordinator
May 28, 2014 at 3:36 PM
And these are the only unwanted blank lines in that file, or are there others?

Also, if you do Run Custom Tool repeatedly on T4MVC, is it really random between lines/no lines, with no discernible pattern?
May 28, 2014 at 3:55 PM
No, there're extra blank lines everywhere. This is just an example I thought would be easier to address since it's before anything else.
Running Custom Tool several times doesn't seem to change number of random lines. It's constant, either they're there, or not.

I suspect it might be related to "* text=auto" attribute in git, which automatically converts all to LF. I tried to disable it and it seems to be working better on machines. Perhaps messing with line ending in .tt forces template tool to add blank lines. Still, I'm not 100% sure it fixed everywhere or that it is actually related. When it was on, on some machines files were generated fine, without all the extra lines.
Coordinator
May 28, 2014 at 6:34 PM
Yes, that could affect it. To remove that from the equation, you should try manually copying the .tt file from working machines to broken machines.

If the input .tt file is not identical, then the different machines are not testing the same scenario.