Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress a warning for all projects in Visual Studio

Tags:

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#.)

like image 382
ispiro Avatar asked May 17 '18 19:05

ispiro


People also ask

How do I suppress SQL warnings in Visual Studio?

In Visual Studio, you have to set the warning(s) to ignore for each individual database object in the project. Select the file and add the warning(s) to ignore in the Suppress TSql Warnings entry in the File Properties window. Do this for each file.

How do I ignore a warning code in Visual Studio?

Use a #pragma warning (C#) or Disable (Visual Basic) directive to suppress the warning for only a specific line of code.

How do I turn off error warnings?

You can make all warnings being treated as such using -Wno-error. You can make specific warnings being treated as such by using -Wno-error=<warning name> where <warning name> is the name of the warning you don't want treated as an error. If you want to entirely disable all warnings, use -w (not recommended).


1 Answers

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 
like image 189
John Koerner Avatar answered Sep 18 '22 12:09

John Koerner