6

I have following namespaces in my project.

enter image description here

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.

fhnaseer
  • 7,159
  • 16
  • 60
  • 112
  • ``~T:Project.ViewModels`` doesn't seem a valid namespace – ganchito55 May 16 '19 at 09:16
  • @ganchito55 I tried without `~T` as well, but it doesn't work. – fhnaseer May 16 '19 at 10:01
  • @AlessandroD'Andria this will suppress warning for whole project, I only want to suppress for one namespace. – fhnaseer May 16 '19 at 10:01
  • The suppressmessage attribute didn't work for me in this case. For those of you who want to go the MSBUILD way, here's the link: http://lvquoc.blogspot.com/2010/11/disable-xml-comment-warning-in-workflow.html Looks like a hardcore-approach but looks promising. – Matt Jun 30 '20 at 12:30

1 Answers1

10

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")]
Joel B
  • 12,082
  • 10
  • 61
  • 69