如何在 Visual Studio 2019 中使用 editorconfig?

How do I use editorconfig in Visual Studio 2019?

我使用以下设置在 VS 2019 的解决方案级别创建了 .editorconfig 文件:

root = true

# All files
[*]
indent_style = tab
indent_size = 4
tab_width = 4

然后我重新启动了 IDE 让更改生效。但是只有 .editorconfig 文件本身使用选定的设置。我的解决方案中的所有其他文件仍然使用空格而不是配置中定义的设置。

然后我将 .editorconfig 文件放在项目级别并再次重新启动。没有变化。

如何正确使用 .editorconfig 文件,以便我的所有项目文件都使用其中定义的设置?

注意:我使用的是最新版本的 VS 2019 Community。

根据文档,您必须使用 "Format Document" 或 "Code cleanup" 将格式应用于现有代码。

When you add an EditorConfig file to your project in Visual Studio, new lines of code are formatted according to the EditorConfig settings. The formatting of existing code is not changed unless you run one of the following commands:

  • Code Cleanup (Ctrl+K, Ctrl+E), which applies any white space settings, such as indent style, and selected code style settings, such as how to sort using directives.
  • Edit > Advanced > Format Document (or Ctrl+K, Ctrl+D in the default profile), which only applies white space settings, such as indent style.

Source: https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2019