Suppress a warning for all projects in Visual Studio

ispiro picture ispiro · May 17, 2018 · Viewed 10.8k times · Source

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 for all of my projects.

(If it matters, the warning is IDE0044. And I'm using C#.)

Answer

John Koerner picture John Koerner · May 17, 2018

A recent update to Visual Studio 2017 (15.7.1) has an option for this now. Under the Tools->Options menu, select the TextEditor->C#->Code Style->General tab. Under Field preferences, there is a Prefer readonly option. Set that to No.

Image of the text editor preferences.

There is also an editorconfig setting you can set if you want to check this preference in along side your code, so others who consume your code don't get the warning, but that has to be done on a per solution basis. The editorconfig value you would set would be:

 dotnet_style_readonly_field = false:none