One of the features included in Visual Studio 2017's first Release Candidate (RC) was support for the EditorConfig standard. Adhering to this standard allows developers to define a coding style once and then easily reuse that style across different editors. Another big advantage is that the styles defined in an EditorConfig file can be stored in a source control system and avoid being lost in a particular editor’s dialog boxes or configuration. VS2017 will support the use of the EditorConfig functionality with several languages, including C#, Visual Basic, C++, JavaScript, F# and TypeScript.
As Microsoft’s Kasey Uhlenhuth explains, one of the benefits of EditorConfig is that broad standards can be defined solution-wide, with additional EditorConfig files uses to define project or directory specific standards. Adding these files allows for the definition of both code formatting rules and code style rules. VS2017RC currently supports these five formatting rules:
- indent_style
- indent_size
- tab_width
- end_of_line
- charset
Two more popular rules, trim_trailing_whitespace
and insert_final_newline
, are not yet supported. Code Style rules can also be defined, and depending on the severity (none / suggestion / warning / error) a build break when this mechanism is fully implemented (currently in VS2017RC a build will proceed). According to Microsoft EditorConfig support in Visual Studio can and will be updated after VS2017 RTM and their goal is provide full compliance with EditorConfig features through the course of these updates.
Once a developer has defined the various Code Formatting and Code Style rules that they want for an existing source tree, it will be necessary to close and reopen any open files or when an EditorConfig file changes. Uhlenhuth provides a couple of keyboard shortcuts to quickly apply new rules:
- Updating a single open file in the editor: Format Document CTRL-K, D
- Apply updates to all files in the entire project/solution: Quick Actions menu CTRL + (control plus)
Note that when an EditorConfig file is present, its rules will override those used defined in Visual Studio’s Tools | Options
menu. If you would like to have some editor conveniences when editing EditorConfig files within VS0217, Mads Kristensen has produced the open source EditorConfig Language Service plugin. Currently using Code Formatting and Style requires VS2017RC, but a NuGet package is being developed to provide this functionality to allow for integration with build systems.
Updated January 10, 2017 to incorporate information on language support and the availability of future updates.