如何从EditorConfig文件将代码约定(代码格式设置)导入Visual Studio?
我希望.editorconfig
所有解决方案都有一个文件,而每个项目都没有一个文件。
Visual Studio 2017和更高版本中支持EditorConfig。
如果愿意,您可以创建一个空文本文件,然后添加所需的设置。但是,Visual Studio可以.editorconfig
为您创建具有合理默认值的.NET文件。从MSDN:
从菜单栏中,选择“项目” >“添加新项”;或按Ctrl + Shift + A
选择editorconfig File (.NET)
模板以添加一个预填充有默认.NET代码样式,格式和命名约定的EditorConfig文件
在Visual Studio 2019中,您可以改为从当前设置创建EditorConfig文件。只需在“选项”对话框中单击以下按钮Text Editor > C# > Code Style > General
:
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.
如果您使用的是Visual Studio 2019,建议您使用Generate .editorconfig file from settings
上面详述的按钮,然后将.editorconfig
文件保存到解决方案文件夹中。否则,您可以创建一个一次性项目,创建配置文件,然后将该文件剪切并粘贴到该文件所在的文件夹中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句