c# - Visual Studio:抑制命名空间中所有文件的警告
问题描述
我的项目中有以下命名空间。
我想禁用特定命名空间上的特定警告(比如说 Project.ViewModels)。我可以通过在GlobalSuppression.cs
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Formatting", "RCS1057:Add empty line between declarations.", Justification = "<Pending>", Scope = "type", Target = "~T:Project.ViewModels.MainViewModel.cs")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Formatting", "RCS1057:Add empty line between declarations.", Justification = "<Pending>", Scope = "type", Target = "~T:Project.ViewModels.TreeViewModel.cs")]
我试图Scope
从type
to更改namespace
,namespaceanddescendants
但它没有工作。
[assembly: SuppressMessage("Formatting", "RCS1057:Add empty line between declarations.", Justification = "<Pending>", Scope = "namespace", Target = "~T:Project.ViewModels")]
知道如何解决这个问题吗?我正在使用 Visual Studio 2017。
解决方案
您不应该将~T:
用于命名空间,这似乎仅适用于类型。对于一个使用示例,您可以在此处查看 .NET Core 代码中的命名空间如何不使用它。此外,仅来自文档 namespace
:
禁止对命名空间本身发出警告。它不会抑制针对命名空间内的类型的警告,如下所示:
根据您的文件层次结构,您可能希望使用namespaceanddescendants
如下所示:
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Formatting", "RCS1057:Add empty line between declarations.", Justification = "<Pending>", Scope = "namespaceanddescendants", Target = "Project.ViewModels")]
推荐阅读
- javascript - 如何重新触发包含 setTimeout 回调和动画的点击元素
- c# - 域别名 - 如何确定 .net core 3.1 中使用了哪一个?
- sql - 尝试通过传递数据库名称和模式以及表名来获取列
- c++ - 调用“enqueue_work”时出现问题 - vorbrodt thread_pool
- html - 为什么 z 轴在 transform-origin 属性中不起作用?
- jenkins - Jenkinsfile 不考虑分支条件
- java - 如何正确限制 JVM 的内存使用量?
- ios - 从github下载为zip文件后如何将应用程序源代码添加到xcode
- flutter - 如何使用 StreamBuilder 在 pdf 中打印来自 Firebase Storage 的图像
- node.js - nodejs twitter如何结束流并开始一个新的