如何为所有解决方案将EditorConfig文件导入Visual Studio? [英] How to import an EditorConfig file into Visual Studio for all solutions?

查看:51
本文介绍了如何为所有解决方案将EditorConfig文件导入Visual Studio?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从EditorConfig文件将代码约定(代码格式设置)导入Visual Studio?

我希望所有解决方案都有一个 .editorconfig 文件,而不是每个项目一个.

解决方案

Visual Studio 2017和更高版本中支持EditorConfig.

创建EditorConfig文件

如果愿意,可以创建一个空文本文件,然后添加所需的设置.但是,Visual Studio可以为您创建具有合理默认值的 .editorconfig 文件.来自

Visual Studio 2019-从当前设置创建EditorConfig文件

在Visual Studio 2019中,您可以改为

在解决方案中共享EditorConfig

要在解决方案和项目之间共享设置,您需要在顶级目录/解决方案文件夹中创建一个 .editorconfig 文件.例如,我在我的主干中,并将其提交给源代码管理,以便我的同事共享相同的设置.

此文件中的设置适用于干线和子文件夹中的所有项目,除非被文件夹树下的另一个 .editorconfig 文件覆盖,例如.您可能在子文件夹中有一个项目特定的EditorConfig文件,该文件具有不同的设置.您无需导入"文件-应该会自动检测到该文件.

请参见 解决方案

EditorConfig is supported in Visual Studio 2017 and newer.

Creating an EditorConfig file

If you like you can create an empty text file and just add the settings you want. However, Visual Studio can create a .editorconfig file with sensible defaults for .NET for you. From MSDN:

  • From the menu bar, choose Project > Add New Item; or press Ctrl+Shift+A

  • Select the editorconfig File (.NET) template to add an EditorConfig file prepopulated with default .NET code style, formatting, and naming conventions

Visual Studio 2019 - Creating an EditorConfig file from current settings

In Visual Studio 2019, you can instead create an EditorConfig file from your current settings. Just click the following button in the Options dialog under Text Editor > C# > Code Style > General:

Sharing an EditorConfig across solutions

To share settings across solutions and projects, you need to create a .editorconfig file in a top-level directory/solutions folder. For example, I have mine in trunk and I commit it to source control so that my colleagues share the same settings.

The settings in this file apply to all projects in trunk and subfolders, unless overridden by another .editorconfig file further down the folder tree e.g. you might you have a project specific EditorConfig file in a subfolder which has different settings. You don't need to "import" the file - it should be detected automatically.

See File hierarchy and precedence for more details.

If you're using Visual Studio 2019, I suggest you use the Generate .editorconfig file from settings button detailed above, and save the .editorconfig file to your solutions folder. Otherwise, you can create a throwaway project, create the config file, and then cut and paste that file to the folder where it needs to live.

这篇关于如何为所有解决方案将EditorConfig文件导入Visual Studio?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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