格式化(4个空格)Visual Studio中的所有代码文件?

Format (4 spaces) all code files in Visual Studio?

我在一个旧分支 feature/old-request 上工作,那个分支没有 .editorconfig 文件通知 Visual Studio 使用 4 个空格(公司同意的格式)。

所以在我的旧分支上,Visual Studio 使用的是我自己的个人设置(2 个空格)。现在我正在尝试合并分支(developfeature/old-request),我得到了很多更改的文件,唯一的变化是间距。

我现在中止了合并,然后从 develop 分支中取出相同的 .editorconfig 文件并将其放在我的 feature/old-request 分支中。

我不喜欢打开 100 多个文件并按 Ctrl + K Ctrol + D.

有没有办法告诉Visual Studio格式化所有代码文件?

在 dotnet CLI 中有一个非常好的工具:dotnet-format

也可以直接从命令行安装:

dotnet tool install -g dotnet-format

现在,当您的目录具有如下解决方案设置时:

path to solution catalog
-- ConsoleApp
-- .editorconfig
-- ConsoleApp.sln

(这只是示例解决方案)。

现在,运行 在解决方案目录中命令 dotnet-foramt,它会自动将 .editorconfig 中的设置应用到您的解决方案。