Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export Visual Studio's 'Code Style settings' as .editorconfig

Our team works with Visual Studio 2017 Professional.

I've been trying to unify the Code Style across the team and apparently the industry standard right now is to use .editorconfig files. Even Visual Studio in it's settings windows suggests to use that configuration file and links to a useful page on how to write an editorconfig file.

but I don't want to write all the settings that I already have configured in VS by hand. I would like a tool that exports those settings as a .editorconfig file to distribute them.

I haven't been able to find any tool to do just that so I thought on righting it myself and share it with other people like me. But apparently if go to "Tools -> Import and Export Settings..." you can't download your current Code Style settings.

Is there a way around this?

do you know any tool to convert my settings to an editorconfig file or a way to export my current Code Style settings?

Edit

I have created my own version of the .editorconfig file based on the information found in here

You can find it in my github repo

like image 918
Daniele Pozzobon Avatar asked Jul 16 '18 07:07

Daniele Pozzobon


People also ask

How do I export visual code settings?

Open control panel ctrl+shift+p and select an action: Import Setting. Export Setting.

How do I export Visual Studio settings?

Export a configurationOpen the Visual Studio Installer. On the product card, choose the More button, and then select Export configuration. Browse to or type the location where you want to save your .

What is a .EditorConfig file?

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.

Where is .EditorConfig located?

editorconfig file at the root of your repo or in the directory that your project resides. Visual Studio looks for a file named . editorconfig in the directory of the opened file and in every parent directory.


2 Answers

I realise this isn't much help for VS2017 users, but VS2019 has a button "Generate .editorconfig file from settings" on the Code Style options page:

This options page is available at Tools > Options > Text Editor > [C# or Basic] > Code Style > General.

options window with proper section selected displaying Generate .editorconfig file from settings button

like image 183
Dave Avatar answered Oct 21 '22 21:10

Dave


I know this question is ancient but worth an answer...

The latest Visual Studio extension allows you to do this (Guide here):

Basically install the extension and right click on the solution or project (you can restrict the rules to solution/project or even folder) and click add > new EditorConfig (IntelliCode)

There are still some restrictions about what you can do in the latest releases of Visual Studio, but Visual Studio 2017 15.8 Preview 3 or higher allow you to use a new extended “Format Document” command to perform additional code cleanup for the current document.

It's a shame you can't make all your rules cause build errors, only some of the options allow this - without this, a lot of the styling options can be ignored.

like image 26
Percy Avatar answered Oct 21 '22 21:10

Percy