Set Visual Studio Formatting Options for an entire team

荒凉一梦 提交于 2019-12-20 16:31:27

问题


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?


回答1:


With 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 VS2017(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

The IntelliCode experimental extension has a feature for generating editor config files, see this blog post for more information.




回答2:


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



来源:https://stackoverflow.com/questions/11684457/set-visual-studio-formatting-options-for-an-entire-team

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!