.net - 如何配置 StyleCop 以抑制生成代码的警告?

标签 .net visual-studio code-generation code-analysis stylecop

另一个项目,Visual Studio 的代码分析有这个选项。但是我在 StyleCop(又名源分析)中找不到它。
我想忽略的文件是 dbml 的 .designer.cs 代码,其中包括 // <autogenerated>标签。 A blog post告诉我它就足够了,但在我的情况下它不是。

最佳答案

StyleCop: How To Ignore Generated Code

编辑:这是我在为 ANTLR 生成的语法中使用的标题。这实际上是一个 StringTemplate 模板的主体,所以两个 \>条目实际上只是转义了 >分数。除了 <auto-generated>标签和 [GeneratedCode]属性,我们仍然必须禁用代码分析过程中出现的一些警告。

//------------------------------------------------------------------------------
// \<auto-generated>
//     This code was generated by a tool.
//     ANTLR Version: ANTLRVersion
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// \</auto-generated>
//------------------------------------------------------------------------------

// $ANTLR <ANTLRVersion> <fileName>

// The variable 'variable' is assigned but its value is never used.
#pragma warning disable 219
// Unreachable code detected.
#pragma warning disable 162
// Missing XML comment for publicly visible type or member 'Type_or_Member'
#pragma warning disable 1591
// CLS compliance checking will not be performed on 'type' because it is not visible from outside this assembly.
#pragma warning disable 3019
// 'type' does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute.
#pragma warning disable 3021

[System.CodeDom.Compiler.GeneratedCode("ANTLR", "<ANTLRVersion>")]
[System.CLSCompliant(false)]
public class ...

关于.net - 如何配置 StyleCop 以抑制生成代码的警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1590238/

相关文章:

.net - LINQ to SQL Transaction.Complete 与 DataContext.SubmitChanges

c++ - 防止控制台窗口在 Visual Studio 2017 cmake 项目中关闭

java - 可转换为 Java 和 XSLT 的规则或脚本语言

.net - 在单元测试 HttpClient 时如何模拟 GetDiscoveryDocumentAsync?

c# - ConfigurationManager 返回 null 而不是字符串值

c# - .NET 5.0 或 .NET Framework 3.5 用于在 Windows 7+ 上部署?

JavaPoet 通用参数

visual-studio-2010 - 没有 Visual Studio 2010 的 T4 代码生成?

c# - 在 C# 中的枚举之间进行转换

c++ - VS 15 社区无法创建 C++ 项目