How Can I Share Visual Studio 2017 Code Style and Formatting?
Asked Answered
S

2

6

My team wants to share our code styling and formatting. We've been using Resharper for this and wanted to take advantage of the new native features in VS2017! What is the best way to do this?

Shocking answered 8/3, 2017 at 18:14 Comment(0)
P
12

.editorconfig!

Visual Studio 2017 will now respect settings from a .editorconfig file if it exists on disk, up to the project root. Currently this is supported on a per-project basis, not on a solution level (I believe R# may have supported this in the solution folder).

Almost every editor in VS should support basic editorconfig options, such as:

  • indent_style
  • indent_size
  • tab_width
  • end_of_line

Additionally, some languages also provide support for language-specific style guidelines. For .NET, see here.

Specifically for C# or VB, if you've configured your settings in VS Tools-> Options, there is also an option to generate an .editorconfig file capturing those settings:

Tools -> Options -> Text Editor -> C# -> Code Style, showing the button to generate .editorconfig settings

Phaedrus answered 8/3, 2017 at 18:48 Comment(3)
How do I port VS settings to editorconfig? What's the point of having an extensive menu system for setting up my editor if I'm forced to use a config file anyway?Laughry
@Laughry I believe the extensive formatting rules predated the .editorconfig support, but now there's an export button. I've updated the answer to show it, thanks for reminding me.Phaedrus
Are you sure the "Generate .editorconfig file from settings" button is available in VS 2017? I can only find it in VS 2019, and this MSDN document says it is only available in VS 2019: learn.microsoft.com/en-us/visualstudio/ide/…Tirade
M
0

Use this extension to generate code style and formatting options that integrate with your source control to effortlessly share solution-level settings. https://marketplace.visualstudio.com/items?itemName=SchabseSLaks.Rebracer

Maya answered 26/9, 2018 at 3:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.