skip to Main Content

I have recently switched from Visual Studio 2019 to 2022 and am working on a C# project that uses tab and indent size 3. I used the same tabs settings for both.

For some reason I can’t figure out however, VS 2022 breaks indentation below any block of code that has been pasted or auto-completed. It looks like it is attempting to reformat with a size 4 indentation but I could be wrong on that (see here before and after auto-complete).

I have not used an .editorconfig file and could not find one anywhere in the folder structure. I have also tried disabling all my extensions and resetting my settings to no avail. Does anyone have an idea what might be the cause here?

EDIT

Since then I have tried the suggestions of Lei Zhang-MSFT but playing with the ‘format on paste’ and ‘adaptive formatting’ parameters did not change anything and creating an .editorconfig file from the ‘Add item’ menu doesn’t seem to do anything (it didn’t show an error but did not create the file). I have also attempted a repair and a full reinstall but that didn’t change anything so it seems likely that this is somehow related to the project itself.

SOLUTION

I can now confirm that it was indeed a bug as Jiale Xue – MSFT suggested. Updating to VS2022 17.4.2 solved the issue.

2

Answers


  1. You can add the EditorConfig file to the project.

    1.From the menu bar, choose Project > Add New Item

    2.In the search box, search for editorconfig.

    enter image description here

    Reference Links:

    https://learn.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2022

    Another method:

    In Tools->Options disable Automatic formatting on paste and Use adaptive formatting
    enter image description here

    enter image description here

    Hope it can help you

    Login or Signup to reply.
  2. This is a bug in the Visual Studio 17.4.1.

    A fix for this issue has been internally implemented and is being prepared for release.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search