How do I import code conventions (code formatting settings) from an EditorConfig file into Visual Studio?
I would like to have one .editorconfig
file for all solutions and not one per project.
How do I import code conventions (code formatting settings) from an EditorConfig file into Visual Studio?
I would like to have one .editorconfig
file for all solutions and not one per project.
EditorConfig is supported in Visual Studio 2017 and newer.
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
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
:
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
files for C++
, C#
and Javascript
. Is it possible to have multiple .editorconfig
files at the solution level, e.g. because the solution incorporates one C#
and one C++
project? (I believe it is not possible, because it seems that the .editorconfig
file must have exactly that name). –
Paleo Put the .editorconfig in a base folder shared by all of your repositories.
Visual Studio and VS Code will pick it up from there for all your workspaces.
If you cloned your code using the Visual Studio default location, then the common base folder will be %USERPROFILE%\source\repos\
© 2022 - 2024 — McMap. All rights reserved.