缩进在Visual Studio .cshtml文件中被破坏 [英] Indentation is broken in Visual Studio .cshtml files

查看:98
本文介绍了缩进在Visual Studio .cshtml文件中被破坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是最令人毛骨悚然的事情,经过45分钟的谷歌搜索和测试后,我陷于论坛之神……即使没有自动缩进,我也无法生存,即使只是在.cshtml视图文件中也是如此

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

我正在使用VS2015社区版.到现在为止,我的cshtml文件都播放良好...

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:

  • 选择标记,然后按Ctrl + K和Ctrl + F
  • 删除并重新添加结束标记(通常会重置缩进)
  • 进入工具">选项">文本编辑器"> [插入语言或所有语言]>标签 并将它们设置为智能.
  • Selecting the markup and hitting Ctrl+K and Ctrl+F
  • Removing and re-adding the closing tag (usually resets indents)
  • Going into Tools>Options>Text Editor>[insert language-or-all]>Tabs and setting them to smart.

在发现问题之前,我刚刚安装了ReSharper.不知道是不是由它引起的,但是问题确实是新的,我不记得在那之前见过.

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>

推荐答案

您提到您是在开始出现此问题之前安装Resharper的,所以您的问题很可能是由R​​esharper引起的.

You mentioned that you just installed Resharper before this problem started occurring, so your problem is most likely being caused by Resharper.

默认情况下,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.

您可以通过Resharper > Options > Code Editing > HTML|Razor|etc > Formatting Style

在这种情况下,您的问题是设置Do not indent children of包含默认情况下不需要的标签.

In this case, your problem was the setting Do not indent children of contained tags that you didn't want by default.

这篇关于缩进在Visual Studio .cshtml文件中被破坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆