isp*_*iro 13 .net c# suppress-warnings visual-studio
我已经看到答案显示如何抑制特定代码行或特定项目的警告.我不希望这样.
我想要禁止所有项目的特定警告.
(如果重要,警告是IDE0044.我正在使用C#.)
Visual Studio 2017(15.7.1)的最新更新现在有一个选项.在Tools->Options菜单下,选择TextEditor->C#->Code Style->General选项卡.在Field preferences,有一个Prefer readonly选项.设置为No.
editorconfig如果要在代码旁边检查此首选项,还可以设置一个设置,因此使用代码的其他人不会收到警告,但必须在每个解决方案的基础上完成.editorconfig您将设置的值为:
dotnet_style_readonly_field = false:none
Run Code Online (Sandbox Code Playgroud)
您可以使用命名空间SuppressMessage下存在的属性,System.Diagnostics.CodeAnalysis如
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "args")]
Run Code Online (Sandbox Code Playgroud)
好吧,正如您所编辑的那样,我想为我的所有项目取消特定警告
对于整个项目明智的 AFAIK,您不能这样做。但是如果有帮助,请检查链接的帖子一次
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.
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
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:
如果您在文本编辑器中创建,您可能需要在文件顶部添加此内容,并根据需要进行调整:
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true
# C# files
[*.cs]
Run Code Online (Sandbox Code Playgroud)
要专门禁用 IDE0044,请在文件中添加或更改以下设置.editorconfig:
dotnet_style_readonly_field = false:none
Run Code Online (Sandbox Code Playgroud)
(在 Visual Studio 2019 中,您可以在“选项”中将该Prefer readonly选项设置为No“下” ,然后按下上面详细介绍的按钮)。TextEditor-> C# -> Code Style-> GeneralGenerate .editorconfig file from settings
| 归档时间: |
|
| 查看次数: |
4931 次 |
| 最近记录: |