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.
In VSCode you need to install an add-in called EditorConfig. This doesn't enable the . editorconfig even if it is telling you about it. Maybe it actually does, but it doesn't work with C# because Omnisharp does something.
The EditorConfig project consists of a file format for defining coding styles and a collection of text editor plugins that enable editors to read the file format and adhere to defined styles. EditorConfig files are easily readable and they work nicely with version control systems.
Use an EditorConfig file when you want to enforce coding styles for all contributors to your repo or project. You can manually populate your EditorConfig file, or you can automatically generate the file based on the code style settings you've chosen in the Visual Studio Options dialog box.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With