Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio indentation set to two spaces instead of four space tab

I have just opened an old project here at work. Someone appears to have changed the indentation. Its set to 2 spaces instead of four space tabbing.

enter image description here

What I have tried:

  1. I tried doing a Cntrl K + D but that hasnt changed it back to proper indentation.
  2. I Deleted the _ReSharper.Caches directory and a new one is just created no change to the indentation.

When those didn't work i have started comparing settings in my visual studio with two different solutions.

Resharper settings spear to be identical ad are the settings in visual studio.

Re-sharper settings

enter image description here

Visual studio settings

enter image description here

Which makes me think this must be in one of the project files or something? If its not an issue with the settings in my visual studio whats overriding the tabbing?

Of note when the project loads i swear it loads with proper indentation and then its reformatted in the last second. Not sure it matters but the projects are .net core 1.0 there are three projects in the solution all three appear to be affected.

Hope someone has a fix for this its really hard to read it like this.

like image 424
DaImTo Avatar asked Mar 20 '18 07:03

DaImTo


People also ask

Should tabs be 2 or 4 spaces?

1. Indentation: tabs vs spaces. Java: 4 spaces, tabs must be set at 8 spaces. Both are acceptable.


2 Answers

Visual Studio may be using an .editorconfig file in the project's directory (or in any parent directory) which allows for a consistent code style within a codebase regardless of user settings.

Visual Studio should indicate this in the lower left-hand area of the IDE window.

If this is the case, you'll need to modify .editorconfig and define a new style in order to change the configuration for the automatic formatting tools.

like image 102
yaakov Avatar answered Sep 22 '22 13:09

yaakov


As people says in answers and comments this is probably a .editorconfig. In our case a developer started using VS Code and when upgrading to VS 2017 Visual Studio also accepts these files.

This was the value in the file that was automatically added:

[*]
end_of_line = crlf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

By adding this we could use C# normally and the developer who wanted to use VS Code could continue to do that:

[*.cs]
indent_style = space 
indent_size = 4

https://developercommunity.visualstudio.com/content/problem/44231/cant-set-indent-level-to-4-spaces-in-vs-2017.html

like image 29
Ogglas Avatar answered Sep 24 '22 13:09

Ogglas