如何启用 CAxxxx 警告?

How to enable CAxxxx warnings?

如何启用代码风格警告,如 CA1002: Do not expose generic lists(或任何其他 "Code Analysis for Managed Code Warnings")?

部分link是:

When to Suppress Warnings

Do not suppress a warning from this rule unless the assembly that raises this warning is not meant to be a reusable library. For example, it would be safe to suppress this warning in a performance tuned application where a performance benefit was gained from the use of generic lists.

这让我想到,编译器应该以某种方式显示此警告。

我试过这段代码(根据 this question,这似乎是 CA1002 的原因):

public FooList : List<Foo>
{
}

编译正常,没有警告。我每个项目的警告级别已经达到最高级别 4:

那么如何启用警告?

代码分析警告与编译器警告是分开的,并且在项目属性的 "Code Analysis" 选项卡上启用。

来自MSDN的详细说明:

  1. In Solution Explorer, right-click the project, and then click Properties.
  2. In the properties dialog box for the project, click Code Analysis.
  3. Specify the build type in Configuration and the target platform in Platform.
  4. To enable or disable automatic code analysis, select or clear the Enable Code Analysis on Build check box.