Configure Visual Studio to use UNIX line endings

Visual StudioVisual Studio-2005Line EndingsEnd of-Line

Visual Studio Problem Overview


We would like to use Visual Studio 2005 to work on a local copy of an SVN repository. This local copy has been checked out by Mac OS X (and updates and commits will only be made under Mac OS X, so no problem there), and as a consequence the line endings are UNIX-style.

We fear that Visual Studio will introduce Windows-style line endings. Is it possible to force Visual Studio to use UNIX line endings?

Visual Studio Solutions


Solution 1 - Visual Studio

Warning: This solution no longer works for Visual Studio 2017 and later. Instead, both of the answers by jcox and Munther Jaber are needed. I have combined them into one answer.

As OP states "File > Advanced Save Options", select Unix Line Endings.

This will only affect new files that are created. Fixing any that were previously created can be done file-by-file or you can search for tools that will fix on-bulk.

Solution 2 - Visual Studio

Here are some options available for Visual Studio Community 2017

  1. "File > Advanced Save Options" has been removed by microsoft due to "uncommon use". Whatever that means. https://developercommunity.visualstudio.com/content/problem/8290/file-advanced-save-options-option-is-missed.html You can add it back by going to "Tools>Customize", then "Commands" tab, select the drop down next to "Menu Bar" select "File" then "Add Command">File>Advanced Save Options..". You can then reorder it in the file menu by using "move down".

I don't know if you will have to then set the advanced save options for each and every file, but it might prevent the issue I was having where my Visual Studio kept adding CL RF line endings into my files that were uniformly LF.

  1. But I took it one step further and I added an extension called "Line Endings Unifier" by going to "Tools>Extensions and Updates>Online" and then searching for "line endings" in the search bar to the right. I will use this to automatically force all of my scripts to save with uniform line endings of my choice, but you can do more with it. https://marketplace.visualstudio.com/items?itemName=JakubBielawa.LineEndingsUnifier

  2. strip'em is another solution that does something similar to Line Endings Unifier. http://www.grebulon.com/software/stripem.php

I am not sure how they differ or the advantages/disadvantages of either. I'm mainly using Line Endings Unifier just because it was in the Visual Studio Marketplace. I think I've used all of these methods in the past, but my memory is fuzzy.

Solution 3 - Visual Studio

So I found this problem and the answers very confusing, especially since I primarily develop in Linux and PhpStorm and simply never have these issues.

I found that for Visual Studio 2019, only Munther Jaber's solution worked when combined with @jcox's .editorconfig changes for new files.

However, being unfamiliar with Visual Studio itself, it took me a LONG TIME to find out where the line ending box is...

SO I made a video of how to configure this. https://youtu.be/YfN3igHXTPo

Update: I learned how to make animated GIFs via FFMPEG just so I could embed the video here! enter image description here

Solution 4 - Visual Studio

VS2017 supports .editorconfig files, which can be checked in along with your project. This is the relevant command for setting Unix line endings:

end_of_line = lf

Solution 5 - Visual Studio

"File > Advanced Save Options", select Unix Line Endings works per file based.

Alternatively You can use Strip'em Add-in for Visual Studio

This Add-in converts the text format of a file when it is saved in Visual Studio.

More info here: http://www.grebulon.com/software/stripem.php

Solution 6 - Visual Studio

There are some VS extension that are useful to solve this problem I will recommend Trim line ends on save. This extension is free and open source. There are similar extensions that may work for you, just go to TOOLS | Extensions and Updates and search online for "line end"

Solution 7 - Visual Studio

For Visual Studio 2019 for Mac

Go to Project> Solution Options> Source Code> Code Formatting> Text File In the Line Terminations drop box select Unix/Mac.

Image

Solution 8 - Visual Studio

enter image description here The LF is clickable and you choose either LF or CRLF.

Solution 9 - Visual Studio

It is possible to force line endings in Visual Studio 2017 for Mac

  1. Go to Tools > Add Custom Tool....
  2. In the dialog box that appears scroll the left menu down to the Text Editor section and select General.
  3. In the first option, Line ending conversion, change Leave line endings as is to Always convert line endings.

screenshot of dialog

Solution 10 - Visual Studio

In the latest version on Windows you go to

File > Preferences > Settings > Text Editor > Files > Eol

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmoalaView Question on Stackoverflow
Solution 1 - Visual StudioZeroView Answer on Stackoverflow
Solution 2 - Visual StudioFragmentalStewView Answer on Stackoverflow
Solution 3 - Visual StudioTheodore R. SmithView Answer on Stackoverflow
Solution 4 - Visual StudiojcoxView Answer on Stackoverflow
Solution 5 - Visual StudioGibboKView Answer on Stackoverflow
Solution 6 - Visual StudiokamaydView Answer on Stackoverflow
Solution 7 - Visual StudioCarlos MaemoView Answer on Stackoverflow
Solution 8 - Visual StudioMunther JaberView Answer on Stackoverflow
Solution 9 - Visual Studioow3nView Answer on Stackoverflow
Solution 10 - Visual StudiolufcView Answer on Stackoverflow