是否可以从所有 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.
发布评论
评论(4)
如果使用
[GenerateCode]
属性标记类,则可以将 /ignore generatedcode 标志与 FxCop 一起使用,如以下 MSDN 帖子中所述:常见问题解答:如何防止 FxCop 对生成的代码发出警告
您可能必须添加一个新的代码文件并在那里实现新的部分类,以将属性添加到类中:
只需确保在您创建时将所有内容添加到正确的命名空间中即可。创建您的新文件。
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:
Just make sure you add everything to the correct namespace when you create your new file.
添加
[GenerateCode] 属性
去上课。编辑:我的意思是部分具有相同名称的类,正如其他答案所解释的那样。
Add a
[GeneratedCode] attribute
to the classes.EDIT: I meant to partial classes with the same names, as explained by the other answer.
使用生成的代码属性,这里是 博客文章。
命名空间顶部的这个应该可以解决问题:
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:
将语句放在项目根目录下的 GlobalSuppressions.vb 中。
我只有VB示例。
Put statement in
GlobalSuppressions.vb
at root of project.All I have is VB example.