If you are like me, you probably don’t like the constant popup dialogs from Visual Studio and MonoDevelop on the inconsistent line endings. You may not have any idea what I’m talking about but constantly see this in Visual Studio while working with your Unity .cs files
First – what on earth are inconsistent line endings? Let’s look at what happens when you press ENTER on a PC based system vs a Unix based OS like OSX. A PC writes a CR/LF (carriage return / line feed) pair. A LF is ‘n’ or if you like hex 0x0A or 10 in decimal. A CR is ‘r’, 0x0D, 13 respectively. For you c/c++/c# programmers out there you’ve probably seen some string “Hello Worldn” or “Hello Worldrn” – also noting we have a LF and CR/LF
Let’s take the following text….
See cat run
Specifically if you look in a Hex Editor, the bytes in the file look like this on PC (note the highlight 0D 0A)
and like this on a Mac (note the missing 0D)
Why does this happen with Unity and Visual Studio? When Unity creates a C# file, it creates it by default with LF only as shown here.
Visual Studio will open this up without a problem and without notifying you of anything. You aren’t mixing CR/LF with your LF. Now you go ahead and paste some code into here, or use some existing code snippets, or format the document, or rely on some auto-complete/formatting features and they may stick in CR/LF into this doc (as you are editing on a pc). Now you have a file with LF and CR/LF mixed in it. It’s inconsistent, hence you get a dialog box like the first image shown above Visual Studio loads that file.
Also note that if you do tell Visual Studio to normalize the line endings (ie clicking yes in that first dialog) it will fix this issue, but for this file only.
Aha. At last. The big reveal. The big secret orphan annie ovaltine decoder ring thingy reveal (our ending is a bit better but for those that have no idea what I’m talking about check out this video clip here). The fix is actually super simple. Visual Studio has a feature called Quick Launch in the upper right hand corner. Simply search for “line” as shown below, select “Environment->Documents (Change line ending settings)” and UNCHECK “Check for consistent line endings on load”. Voila. Annoyance resolved. Both the Mono and .NET C# compilers will handle mixed line endings just fine, so there’s no problem here with doing this. Btw – if you are using a PC and aren’t using my free “Right click to open folder as Unity project” registry script, check out my blog post on this. Enjoy!
Source: Adam Tuliper