Disable Visual Studio Code Formatting in Razor

The question was previously asked: why doesn't Visual Studio code formatting work properly for Razor markup?

But this issue is a couple of years old. And Razor formatting is still completely unacceptable. I refused the correction.

Can I turn off ALL Visual Studio formatting for CSHTML files? If not, can I completely disable Visual Studio formatting? Any third-party hacks I can use? There must be something!

I upgraded to 2013, and formatting is just as bad.

[EDIT]: 2015 is also a terrible year. I REALLY wish them to fix it.

[EDIT]: 2017 is also a terrible year. I REALLY wish them to fix it.

[AMENDMENT]: 2019 is also a terrible year. I REALLY wish them to fix it.

+91
code-formatting visual-studio razor
Nov 20 '13 at 2:30
source share
9 answers

You can not. This is built into the VS “function” from the first version of .net (visual studio 2002/2003).

There are many reports of connection to formatting errors, but Microsoft ignores them completely or pushes the fix to the “next version”. You can see an example of Microsoft's answer here .

You can leave your feedback in Microsoft Team here

+38
Feb 05 '14 at 7:46
source share

Under Tools → Options → Text Editor → HTML → Advanced

there is a key element of the Paste value that says "Format on insert" and has a boolean value next to it. Changing this parameter to false turned off the formatting on the insert for me in razor syntax.

I am using VS Professional 2013, Version 12.0.30110.00 Update 1

+45
Jan 20 '15 at 19:44
source share

Places to search:

Tools -> Options -> Web Essentials -> HTML -> Auto-format HTML on Enter 

Set to false

 Tools -> Options -> Text Editor -> HTML -> Advanced -> Format on Paste 

Set to false

I have no problems with these settings in Visual Studio 2013.

I used to press Ctrl-Z too often, and if you forgot to unravel the clutter as soon as your code was written and tested, there was a huge pain. I believe that Microsoft can do alot to help users customize this, as well as make it more accessible.

+32
Jun 05 '15 at 14:18
source share

That trick for me pressed CTRL + Z after pasting, then the formatting will be removed.

+22
Jul 16 '14 at 13:49
source share

In my case, R # was the culprit, you can disable it here:

ReSharper> Options> Code Editing> Razor> Editor and Formatting

https://www.jetbrains.com/help/resharper/2016.1/Reference__Options__Languages__Razor__Editor.html

+8
Aug 24 '16 at 16:10
source share

Unfortunately, the only way to prevent auto-formatting from pasting is to comment out the location where you are going to paste the new code, and after the paste operation, delete instructions for comments.

Search and replace do not start automatic formatting. But the insert will reformat the entire block of code.

This is terrible than words. This makes the Visual Studio IDE almost unusable for editing Razor. You need to use an external editor for Razor files.

To make matters worse, even the latest Visual Studio 2013 Update 1 update failed while editing Razor views all the time.

+7
Mar 28 '14 at 16:13
source share

The interesting part: you can turn off C # formatting and HTML formatting, but not Razor formatting.

I unchecked "Tools"> "Options"> "Text Editor"> "C #"> "Formatting"> "Automatically format on insert" and the same goes for HTML.

This leads to the following interesting experience in cshtml files:

  • Embed HTML: no format
  • Paste C # code: no format
  • Paste Razor Code: Formatting Everything Wrong

And since there is no way to change the Razor settings, you have to live with it, I think.

My "solution": paste and ctrl-z to cancel auto format

+6
Aug 27 '14 at 9:20
source share

I found these settings in Resharper 2019 that improved my experience: enter image description here

0
Jun 13 '19 at 8:34
source share

I think this will do:

Tools> Options> Text editor> C #> Formatting> [uncheck] Automatically format the insert

Or try going

Tools | Options → Text Editor | HTML | Miscellaneous and disabling HTML formatting on an insert.

-one
Feb 06 '14 at 1:07
source share



All Articles