Enabling Microsoft's Code Analysis on .NET Core Projects

后端 未结 2 826
天命终不由人
天命终不由人 2020-12-29 03:17

Our team uses the Code Analysis feature with a custom ruleset to cause our build to fail if we forget to do things like null checks on method arguments.

However, now

2条回答
  •  隐瞒了意图╮
    2020-12-29 03:34

    Update

    Apparently the right way to do this is to install the Microsoft.CodeAnalysis.FxCopAnalyzers NuGet package. This works great, even on ASP.NET Core projects, and doesn't require the flag at all.

    Original Answer

    I realized that there's another tag in the csproj file which actually enables code analysis. The tag in my .csproj file now looks like this:

      
        netstandard1.4
        ..\MyCompanyCodeAnalysisRules.ruleset
        true
      
    

    And it works great, at least on normal projects. An ASP.NET Core project is producing the following errors:

    CA0055 : Could not identify platform for 'C:\Source\...\bin\Debug\netcoreapp1.1\....dll'.
    CA0052 : No targets were selected.
    

提交回复
热议问题