I have following namespaces in my project.
I want to disable a specific warning on a specific namespace (lets say Project.ViewModels). I can disable a warning on one files by doing this in the 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")]
I tried to change Scope
from type
to namespace
and namespaceanddescendants
but it didn't work.
[assembly: SuppressMessage("Formatting", "RCS1057:Add empty line between declarations.", Justification = "<Pending>", Scope = "namespace", Target = "~T:Project.ViewModels")]
Any idea how this can be fixed? I am using Visual Studio 2017.
You can suppress violations in code using a preprocessor directive, the #pragma warning (C#) or Disable (Visual Basic) directive to suppress the warning for only a specific line of code. Or, you can use the SuppressMessage attribute.
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule. To disable the rule for a file, folder, or project, set its severity to none in the configuration file.
You shouldn't use the ~T:
for a namespace, that seems to only be for types. For a usage example, you can see how it's not being used for the namespace in the .NET Core code here. Also, from the docs namespace
only:
suppresses warnings against the namespace itself. It does not suppress warnings against types within the namespace as shown below:
Depending on your file hierarchy, you'll potentially want to use namespaceanddescendants
as shown below:
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Formatting", "RCS1057:Add empty line between declarations.", Justification = "<Pending>", Scope = "namespaceanddescendants", Target = "Project.ViewModels")]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With