Reputation: 116868
I have just opened an old project here at work. Someone appears to have changed the indentation. It's set to 2 spaces instead of four space tabbing.
What I have tried:
_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 appear to be identical so are the settings in visual studio.
Re-sharper settings
Visual studio settings
Which makes me think this must be in one of the project files or something? If it's not an issue with the settings in my visual studio, what's overriding the tabbing?
Of note when the project loads I swear it loads with proper indentation and then it's 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; it's really hard to read it like this.
Upvotes: 28
Views: 32023
Reputation: 11
What I have just done but I am no expert, was to go to Tools>>Options. When the Options windows pops, I scroll down to Text Editor>>All Languages>>Tabs. Then, in Tab size and in Indent size, I put, in my case "3", but choose whatever number you prefer, I guess in your case, "4". By the way, if you find "2" in any of/both the cells, it is a first confirmation that it could be the right place for these settings. Please note the environment is Visual Studio 2022.
Upvotes: 1
Reputation: 69928
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
Upvotes: 16
Reputation: 5851
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.
Upvotes: 39