从 FxCop 代码分析中排除完整的命名空间?

发布于 2024-09-17 05:40:16 字数 259 浏览 3 评论 0 原文

是否可以从所有 FxCop 分析中排除完整的命名空间,同时仍然使用 SuppressMessageAttribute 分析程序集的其余部分?

在我当前的情况下,我有一堆由 LINQ to SQL 生成的类,这会导致很多 FxCop 问题,显然,我不会修改所有这些以匹配 FxCop 标准,因为如果我重新生成类。

我知道 FxCop 有一个项目选项可以抑制对生成代码的分析,但它似乎无法将 LINQ 2 SQL 创建的实体和上下文类识别为生成代码。

Is it possible to exclude a complete namespace from all FxCop analysis while still analyzing the rest of the assembly using the SuppressMessageAttribute?

In my current case, I have a bunch of classes generated by LINQ to SQL which cause a lot of FxCop issues, and obviously, I will not modify all of those to match FxCop standards, as a lot of those modifications would be gone if I re-generated the classes.

I know that FxCop has a project option to suppress analysis on generated code, but it does not seem to recognize the entity and context classes created by LINQ 2 SQL as generated code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

ゝ杯具 2024-09-24 05:40:17

如果使用 [GenerateCode] 属性标记类,则可以将 /ignore generatedcode 标志与 FxCop 一起使用,如以下 MSDN 帖子中所述:

常见问题解答:如何防止 FxCop 对生成的代码发出警告

您可能必须添加一个新的代码文件并在那里实现新的部分类,以将属性添加到类中:

[GeneratedCode]
public partial class MainDataContext { }

只需确保在您创建时将所有内容添加到正确的命名空间中即可。创建您的新文件。

If you tag your classes with the [GeneratedCode] attribute, you can use the /ignoregeneratedcode flag with FxCop as described in this MSDN post:

FAQ: How do I prevent FxCop from firing warnings against generated code

You may have to add a new code file and implement new partial classes there to add the attribute to the classes:

[GeneratedCode]
public partial class MainDataContext { }

Just make sure you add everything to the correct namespace when you create your new file.

帅冕 2024-09-24 05:40:17

添加 [GenerateCode] 属性 去上课。
编辑:我的意思是部分具有相同名称的类,正如其他答案所解释的那样。

Add a [GeneratedCode] attribute to the classes.
EDIT: I meant to partial classes with the same names, as explained by the other answer.

梓梦 2024-09-24 05:40:17

使用生成的代码属性,这里是 博客文章

命名空间顶部的这个应该可以解决问题:

[GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]

Use the Generated Code Attribute, heres the blog post from the Code Analysis team on the subject.

This at the top of the namespace should do the trick:

[GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]
挽你眉间 2024-09-24 05:40:17
<Assembly: SuppressMessage("Microsoft.Design", _
    "CA1020:AvoidNamespacesWithFewTypes", _
    Scope:="namespace", _
    Target:="Missico.IO")> 

将语句放在项目根目录下的 GlobalSuppressions.vb 中。

我只有VB示例。

<Assembly: SuppressMessage("Microsoft.Design", _
    "CA1020:AvoidNamespacesWithFewTypes", _
    Scope:="namespace", _
    Target:="Missico.IO")> 

Put statement in GlobalSuppressions.vb at root of project.

All I have is VB example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文