为什么在 VisualStudio2010C # 代码窗口中总是出现混合的制表符和空格?

我刚刚在一个 web 应用程序中处理了一个 C # 文件(Global.asax.cs) ,大约一个小时左右的时间,我已经看到过四次“ tabify”或其他提示。每次我选择制表并保存文件,然而在随后的某个看似随机的点上,我又得到了提示。

我正在使用 ReSharper,但是当我在家里编写代码的时候并没有发生这种情况,也只有在工作的时候才会使用 ReSharper。

28974 次浏览

Are you using the Productivity Power Tools VS 2010 extension? If so, go to Tools -> Options -> and choose Productivity Power Tools. Here you can turn off the option to Fix Mixed Tabs. This will turn off this warning.

Power Tools for Visual Studio 2010

Power Tools for Visual Studio 2012

Power Tools for Visual Studio 2013

Power Tools for Visual Studio 2015

The mixed tabs and spaces might come from your visual studio text editor setting. You can decide if you want visual studio to insert spaces or tabs here:

Tools/Options/ -> Text Editor/All Languages/Tabs, select the "Keep Tabs" option.

Choose the "Untabify" option since VS defaults to spaces, not tabs. If you choose "Tabify" the next time you add a line, VS will use spaces and you'll see the prompt over and over.

Resharper uses seperate tab/space settings to visual studio. In the Resharper options, check "General Formatter Style -> How to align when tabs are used for indents". This setting is used when resharper is formatting code (such as refactoring etc) and defaults to "User Spaces".

Also, in "Edit -> Advanced" menu, there is a "View Whitespace" option (Ctrl + E, S) which may be useful!