Suppress a warning for all projects in Visual Studio

前端 未结 6 1296
心在旅途
心在旅途 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:03

    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.

    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
    

提交回复
热议问题