-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2701d32
commit 9a6edcb
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
"pagefind", | ||
"parameterless", | ||
"routable", | ||
"RSRP", | ||
"shortcode", | ||
"shortcodes", | ||
"SLAAC", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
title: Line Endings in C# Files | ||
topics: | ||
- csharp | ||
- file-format | ||
- visual-studio | ||
- resharper | ||
--- | ||
|
||
In my projects I prefer to use Linux/Unix line endings (`LF`) for all text files (via `.editorconfig`): | ||
|
||
```.editorconfig | ||
[*] | ||
end_of_line = lf | ||
``` | ||
|
||
So ideally, C# files (`.cs`) should also use `LF` as line ending type. | ||
|
||
Unfortunately, this is currently not possible because Linux line endings are not *fully* supported by Visual Studio and ReSharper (my primary editors for C# code). | ||
|
||
Without *full* support, when editing C# files you'd sometimes get Linux line endings (as defined by `.editorconfig`) and sometimes Windows line endings (for features that don't support Linux line endings or `.editorconfig`) - resulting in files with **mixed line endings**. | ||
|
||
In other editors (like Visual Studio Code) this would not be a problem because they **normalize the line endings** when saving a file. Unfortunately, Visual Studio does *not* do this (see [feature request](https://developercommunity.visualstudio.com/idea/1296741/normalize-line-endings-on-save-according-to-editor.html) which has since been closed *without* actually fixing the problem). | ||
|
||
So, for now, the pragmatic approach is to **define line endings for C# files as `CRLF`** (Windows line endings): | ||
|
||
```.editorconfig | ||
[*.cs] | ||
end_of_line = crlf | ||
``` | ||
|
||
{{< tip >}} | ||
To prevent users from accidentally checking in mixed line endings, you should also enforce line endings via `.gitattributes`: | ||
|
||
```.gitattributes | ||
*.cs text eol=crlf | ||
``` | ||
|
||
{{< /tip >}} | ||
|
||
## Bugs | ||
|
||
This section tracks the various bug reports regarding missing Linux line ending support. | ||
|
||
### Visual Studio | ||
|
||
None known. | ||
|
||
### ReSharper | ||
|
||
* [RSRP-478837: Mixed line endings in file templates](https://youtrack.jetbrains.com/issue/RSRP-478837) | ||
* [RSRP-494722: Code insertion (templates) creates wrong line endings](https://youtrack.jetbrains.com/issue/RSRP-494722) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'ReSharper' | ||
--- |