gpt4 book ai didi

c# - Visual Studio : Suppress warnings for all files in a namespace

转载 作者:行者123 更新时间:2023-12-02 09:26:59 27 4
gpt4 key购买 nike

我的项目中有以下命名空间。

enter image description here

我想禁用特定命名空间上的特定警告(比如说 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来自typenamespacenamespaceanddescendants但没有成功。

[assembly: SuppressMessage("Formatting", "RCS1057:Add empty line between declarations.", Justification = "<Pending>", Scope = "namespace", Target = "~T:Project.ViewModels")]

知道如何解决这个问题吗?我使用的是 Visual Studio 2017。

最佳答案

您不应该将 ~T: 用于命名空间,这似乎仅适用于类型。对于使用示例,您可以看到它如何不被用于 the .NET Core code here 中的命名空间。 。另外,from the docs命名空间:

suppresses warnings against the namespace itself. It does not suppress warnings against types within the namespace as shown below:

根据您的文件层次结构,您可能需要使用namespaceanddescendants,如下所示:

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Formatting", "RCS1057:Add empty line between declarations.", Justification = "<Pending>", Scope = "namespaceanddescendants", Target = "Project.ViewModels")]

关于c# - Visual Studio : Suppress warnings for all files in a namespace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56164904/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com