.editorconfig support in Visual Studio 2017

March 11, 2017 by Anuraj

Visual Studio 2017 .editorconfig

This post is about .editorconfig support in Visual Studio 2017. EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs. As part of productivity improvements in Visual Studio, Microsoft introduced support for .editorconfig file in Visual Studio 2017.

Unlike earlier versions, Visual Studio 2017 comes with a coding style configuration option, which you can access from Tools > Options.

Install Live Unit Testing

The .editorconfig file overrides this settings, which helps you to keep the coding style consistant across every one in your team.

To get started, you can create a .editorconfig file in your root directory and configure the coding style. You can find more details about the Style Settings in the docs

.editorconfig file in solution explorer

EditorConfig files use an INI format that is compatible with the format used by Python ConfigParser Library. EditorConfig files should be UTF-8 encoded, with either CRLF or LF line separators. Here is the format, and possible values.

options_name = false|true : none|suggestion|warning|error

Here is one I have created for the demo purposes.

root = true
# Don't use "var" - warning
csharp_style_var_for_built_in_types = false:warning
# Use object initializer and collection initializer
dotnet_style_object_initializer = true:warning
dotnet_style_collection_initializer = true:error

In this I am enforcing 3 coding styles.

  • Don’t use var, show warning.

Don't use var

  • Use object initializer, show warning.

Use object initializer

  • Use collection initializer, show error. Use collection initializer

The root = true specifies this editorconfig file is the root one. And here is the output.

You must close and reopen any open files to have EditorConfig settings apply once it is added or edited.


Happy Programming :)

Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub