22

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

Daniele Pozzobon
  • 381
  • 2
  • 4
  • 11

2 Answers2

13

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

ruffin
  • 16,507
  • 9
  • 88
  • 138
Dave
  • 3,429
  • 2
  • 26
  • 29
  • 3
    Please do not ask questions in answers. Post a new question instead. Otherwise this breaks this Q&A system[s concept and UI]. Comments are not a good way to answer questions. See help and introduction to this website. – Kissaki Jan 27 '20 at 12:52
  • VS 2019 loads the .editorconfig when you open a solution. So while there is no explicit import to import from elsewhere, you can definitely make VS load an editorconfig, make some changes in the code style settings, and then generate/export it again. – Kissaki Jan 27 '20 at 12:52
6

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.

Percy
  • 2,855
  • 2
  • 33
  • 56
  • 1
    The extension infers the settings from your codebase. What if your codebase doesn't follow your rules? Perhaps you inherited code or have decided to use new style guidelines. I can't believe that no one's written anything to convert from the VS rules to .editorconfig. – Tundey Jul 24 '18 at 12:55
  • If the codebase doesn't follow your rules then you either use the tool to create a starting point that you then edit to match your rules or you start from scratch adding only the rules you want – Percy Sep 22 '18 at 09:32
  • 2
    I get that. But is there a GUI for editing the rules? That's what I'm looking for. If I create a starting point from existing code, I get rules I don't want. If I start from scratch, I have to hand write tons of rules. Neither is ideal. – Tundey Sep 23 '18 at 10:41
  • It seems to only generate C# config for me. – riv Jul 25 '19 at 08:34