Turn off auto formatting in Visual Studio

2019-01-04 01:00发布

I'm a code purist, preferring my own style of code formatting as opposed to Visual Studio's default settings. I've turned off auto-formatting options in Tools/options. In most cases it works.

After using any of the built-in refactorings, Visual Studio clobbers my settings with its default settings. How do I keep VS from doing that?

13条回答
2楼-- · 2019-01-04 01:04

In addition to Tango's answer for the actual solution, there may be people actually want to stay current with auto-formats but not have it screw up your relevant changes. I would suggest that you modify the file to have auto-format activate, check in those changes, then proceed with the actual changes you wish to make.

That way your code can stay up to date, but your check in will be relevant.

查看更多
对你真心纯属浪费
3楼-- · 2019-01-04 01:05

I doubt that you can disable re-formatting after refactoring. Refactoring changes code and since it's only text I doubt what you'd want is that it just dumps unformatted text into your source. Wouldn't it be a little easier to just set the code style VS adheres to to the style you like and follow?

查看更多
别忘想泡老子
4楼-- · 2019-01-04 01:06

The reformat on semicolon or closing brace cannot be turned off. I find it infuriating the Microsoft would have the temerity to tell anyone how to format code; the most illegible code I have ever seen was while working there.

I want adjacent assignments to be vertically aligned; VS reformats them to one space on either side of the equal sign irrespective of the length of the variable on the left. This is intolerable. And turning it off on the editor options is ignored; given comments like the opener above I am certain this is deliberate.

Consistency is only a virtue when it leads to desirable outcomes. This is not one.

查看更多
倾城 Initia
5楼-- · 2019-01-04 01:06

As suggest by @TheMatrixRecoder took a bit of finding for me so maybe this will help someone else. VS 2017 option can be found here

Unitick these options to prevent annoying automated formatting when you places a semicolon or hit return at the end of a line.

查看更多
一纸荒年 Trace。
6楼-- · 2019-01-04 01:12

In my case, it was ReSharper.

Test if ReSharper

StackOverflow: How can I disable ReSharper in Visual Studio and enable it again?

Prevent ReSharper from reformatting code

StackOverflow: Is there a way to mark up code to tell ReSharper not to format it?

Update

It was ReSharper in the end:

enter image description here

查看更多
做个烂人
7楼-- · 2019-01-04 01:14

In VS2017 you can change it after selecting your coding language in the settings menu. There is an option called "new Lines" in the "Formatting"-submenu.

查看更多
登录 后发表回答