Different devs on our team have wildly different checkboxes here:
and as a consequence Visual Studio keeps reformatting code and this really pollutes our commits.
What I want is to have a single whatever (.reg
file or something) to run on each devs' computer so that these settings will be consistent.
How can I do this?
As long as your code is syntactically correct (i.e. no stray brackets or End Ifs without matching Ifs), Visual Studio will reformat your whole file with one key chord: Hold down the Control key and then press K, followed by D. Boom!
In an existing project, open the document that you want to format, right-click inside the document, and select Format Document. In the default configuration for Visual Studio Code, the command can be run using the shortcut Alt+Shift+F.
You can format an entire file with Format Document (Ctrl+Shift+I) or just the current selection with Format Selection (Ctrl+K Ctrl+F) in right-click context menu. You can also configure auto-formatting with the following settings: editor. formatOnSave - to format when you save your file.
Starting from VS2017, .editorconfig
files are taken into account and allow to override local preferences. Put it at the root of your projects solution (or even higher), under source control in order to distribute it with your sources to each developer.
You can set .Net coding conventions through VS (since v15.3) specific properties, documented here.
Example file:
root = true [*] end_of_line = CRLF insert_final_newline = true [*.cs] indent_style = tab dotnet_sort_system_directives_first = true csharp_space_after_cast = true [*.xsd] indent_style = tab [*.json] indent_style = space indent_size = 2 [*.xml] indent_style = space indent_size = 2 [*.cshtml] indent_style = space indent_size = 4
For VS2017, the IntelliCode experimental extension has a feature for generating editor config files, see this blog post for more information.
Starting from VS2019, VS can create an editorconfig file from "New File" templates, from your code base (right-click a project > Add > New EditorConfig) or from your current VS configuration (Tools > Options > Text Editor > [C# or Basic] > Code Style > General).
You can export the desired settings from one of the visual studio instances from the tools menu using the option "Import and Export settings". This will save the settings to a .vssettings file (which is actually a xml file) holding stuff like
<PropertyValue name="TabSize">4</PropertyValue>
You can then either import these settings on the other machines through the user interface (same menu option) or you can load them from the commandline using
devenv.exe /Resetsettings <your settingsfile>
This commandline settings is documented here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With