Suppress a warning for all projects in Visual Studio

前端 未结 6 1294
心在旅途
心在旅途 2021-01-04 00:48

I\'ve seen answers showing how to suppress a warning for a specific line of code or for a specific project. I don\'t want that.

I want to suppress a specific warning

6条回答
  •  天命终不由人
    2021-01-04 01:08

    To suppress warnings for all projects, you need to create a .editorconfig file in a top-level directory. For example, I have mine in trunk and I commit it to source control so that my colleagues share the same settings.

    The settings in this file apply to all projects in trunk and subfolders, unless overridden by another .editorconfig file further down the folder tree e.g. you might you have a project specific EditorConfig file in a subfolder which has different settings. See File hierarchy and precedence for more details.

    Creating an EditorConfig file

    You can use a text editor for this if you just want to change one specific setting. However, Visual Studio can create a .editorconfig file with sensible defaults for .NET for you. From MSDN:

    • Create a new project

    • From the menu bar, choose Project > Add New Item; or press Ctrl+Shift+A

    • Select the editorconfig File (.NET) template to add an EditorConfig file prepopulated with default .NET code style, formatting, and naming conventions

    • Optionally delete the project - we don't really need it

    Visual Studio 2019 - Creating an EditorConfig file from current settings

    In Visual Studio 2019, you can instead create an EditorConfig file from your current settings. Just click the following button in the Options dialog under Text Editor > C# > Code Style > General:

    If you're creating in a text editor you'll probably need this at the top of the file, adjusted as necessary:

    # Remove the line below if you want to inherit .editorconfig settings from higher directories
    root = true
    
    # C# files
    [*.cs]
    

    Disabling IDE0044 in the editor config file

    To disable IDE0044 specifically, add or change the following setting in the .editorconfig file:

    dotnet_style_readonly_field = false:none
    

    (In Visual Studio 2019, you can set the Prefer readonly option to No under TextEditor-> C# -> Code Style-> General in Options and then press the Generate .editorconfig file from settings button as detailed above).

提交回复
热议问题