Visual Studio Code Analysis doesnt show CA errors

Rakesh Mallya 1 Reputation point
2020-09-25T07:17:24.48+00:00

When we run the Visual studio code analysis for “Microsoft all rules” in Visual Studio S2019, VS2017 we do not get any CA error codes listed in our project. But it lists only CS error codes ( Ex: CS0105, CS0108, CS0114 etc).

But when we run the same in console using below mentioned msbuild command, it lists several CA error codes in our project such as CA1002, CA1004, CA1006, CA1011 etc.

msbuild ABC.project1.csproj /p:RunCodeAnalysis=true /p:CodeAnalysisLogFile= ABC.project1.Report.MicrosftAllRules.xml

Basically, code analysis report is generated differently from Visual studio vs from the console. Please help why there is a different behavior here.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,577 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,879 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Dylan Zhu-MSFT 6,406 Reputation points
    2020-09-28T06:19:34.107+00:00

    Hi RakeshMallya-9894,

    The CA warning codes are from Fxcop legacy analyzers, which are disabled in visual studio. And the CS warning codes are from Roslyn analyzers, which are working in visual studio.

    When we use msbuild with "RunCodeAnalysis", it will use Fxcop analyzers to analysis your code.

    So if you want to enable Fxcop analyzers in your visual studio, please follow steps bleow:

    1. Install Microsoft Code Analysis 2019(2017) in Extensions/Manage Extensions
    2. Install nuget package: Microsoft.CodeAnalysis.FxCopAnalyzers for your project
    3. The CA warning code will show in 'Error List' window.
    4. Or, please click "Run on Build" in Project Properties/Code Analysis, then you could check them in output window after building the project.

    Best Regards,
    Dylan


  2. zzplural 1 Reputation point
    2021-04-22T09:19:58.66+00:00

    Hi.

    I'm wanting to do the same as the OP.

    But Microsoft Code Analysis 2019 is not showing up in Manage Extensions search results.

    My problem: I've picked up an old .Net Framework 4 solution that has been updated using Visual Studio 2019, and I need to do some quality checks for object disposal (CA2000 etc). There's no chance of this solution being updated to .Net Core.

    One more thing:
    If you switch over to the more modern way of doing code analysis, it appears to require a .editorconfig file to do any useful analysis checks. The Editor Config Language Service extension appears to provide a way of adding a bare bones .editorconfig file to a project. But where would I find any such config file that would be the equivalent to "Microsoft All Rules"? I'd rather not spend days of my time adding entries to an .editorconfig file to give me similar kind of code checks that took place in older versions of Visual Studio (with a few clicks and ticks)!

    0 comments No comments