28
loading...
This website collects cookies to deliver better user experience
.editorconfig
support to Visual Studio. This file defines a set rules that override the local Visual Studio settings. So you can work on multiple projects owned by different teams with their own rules without having to change every time your local Visual Studio settings.IDisposable
object is not properly disposed, or when an async
method is not await
ed..editorconfig
files..editorconfig
file, but personally I don't like it. I think it is way quicker to manually edit it - usually I use VS Code..editorconfig
file by setting:root = true
[*] # Any file uses space rather than tabs
indent_style = space
# Code files
[*.{cs,csx,vb,vbx}] # these files use 4 spaces to indent the code
indent_size = 4
insert_final_newline = true
charset = utf-8-bom
# XML project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 2
# XML config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_size = 2
# JSON files
[*.json]
indent_size = 2
# Powershell files
[*.ps1]
indent_size = 2
# Shell script files
[*.sh]
end_of_line = lf
indent_size = 2
# Dotnet code style settings:
[*.{cs,vb}]
Tools
-> Options
-> Text Editor
-> C#
(or your favorite language) -> Advanced
-> Set Background Analysis Scope
to Entire Solution
This doesn't affect MsBuild
, that instead needs to enable analysers in your csproj
s by checking EnableNETAnalyzers
and EnforceCodeStyleInBuild
!<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
</PropertyGroup>
Async
to any asynchronous method in the solution but for unit tests and controllers..editorconfig
files allow you to achieve a solution quite straightforward. Basically, you have two ways:.editorconfig
file.editorconfig
, define the namespace of where you would like to apply the exception. For example:[src/**{.UnitTests,/Controllers}/**.cs]
# Async methods should have "Async" suffix
dotnet_naming_rule.async_methods_end_in_async.severity = none
root
property we set at the beginning? That means that the given .editorconfig
is applied to the whole solution. But however it is possible to create other .editorconfig
files in subfolders that will inherit all the rules from the root
file. Rules defined here takes the precedence. Getting back the previous example, you can navigate to the Controllers
/UnitTests
folders and create a new file. Do NOT define the root=true
property and add this:# Async methods should have "Async" suffix
dotnet_naming_rule.async_methods_end_in_async.severity = none
Code clean up
. Personally I don't like it for the following reasons:Productivity Power Tools
, an (historical) extensions developed by Microsoft. It provides a feature to format the entire file when the file is saved (through UI or the shortcut CTRL+S). It makes simply impossible to forget to format your file before committing it in your source control.Elders
has published an extension called Format document on Save and it does simply what its name says: it formats the document when the user save it!.formatconfig
that you can check in your source control and share with your team. It doesn't need to be added to the Visual Studio solution, but just to stay in the same level of the solution file. Local user preferences are ignored.root = true
[*.*]
enable = true
enable_in_debug = true
command = Edit.FormatDocument Edit.RemoveAndSort
allowed_extensions = .*
denied_extensions =
.editorconfig
file with lot of rules defined. You can get the remaining ones on Microsoft Docs.