It's the most infuriating thing and after 45 minutes of Googling and testing I caved to the forum gods... I simply cannot live without automatic indentation, even if it's just on .cshtml view files
I'm using VS2015 Community edition. My cshtml files have played nicely until now...
For some odd reason, indentation broke.
I have already tried the obvious:
I had just installed ReSharper before noticing the problem. Not sure if that caused it or not, but the problem is indeed new and I don't remember seeing it before that.
Also odd, some things do indent while others do not
For those that need a visual aid, this indentation frustrates me:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width"/>
<title>Index</title>
</head>
<body>
<h1>Posts Index</h1>
@if (true)
{
<text>
<p>True is true!</p>
</text>
}
</body>
</html>
Go to Home and select Line and Paragraph Spacing > Line Spacing Options at the bottom of the menu. The Paragraph dialog box opens. On the Indents and Spacing tab, select the options you want, and click OK. The Paragraph dialog box options are described in Adjust indents and spacing.
If you prefer using [spacebar] to indent your code rather than using [tab], you can select multiple lines by holding the [alt] key and clicking on the beginning of each line you want to indent. Then, you can press [spacebar] and all the selected lines will be affected.
You mentioned that you just installed Resharper before this problem started occurring, so your problem is most likely being caused by Resharper.
By default Resharper does many extra formatting fixes as you type, but you'll likely find a bunch of these default fixes conflict with your coding style.
You can configure Resharper's code formatting options via Resharper > Options > Code Editing > HTML|Razor|etc > Formatting Style
In this case, your problem was the setting Do not indent children of
contained tags that you didn't want by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With