Search code examples
c#visual-studio-2017.net-4.5code-analysisroslyn-code-analysis

VS 2017 - DotNetAnalyzers Warnings Showing Up in Build Output, But Not Code Analysis


I'm seeing the following in VS 2017 Enterprise on a csproj, Project1, that's being built on .Net 4.5.2:

18>------ Rebuild All started: Project: Project1, Configuration: Debug Any CPU ------
18>C:\git\27844-2-StyleCop\company\Class1.cs(26,31,26,47): warning CS0169: The field 'Class1.field' is never used
18>C:\git\27844-2-StyleCop\company\Class2.cs(31,48,31,69): warning SA1214: Readonly fields must appear before non-readonly fields
18>C:\git\27844-2-StyleCop\company\Interface1.cs(9,45,9,69): warning SA1127: Generic type constraints must be on their own line
18>  Project1 -> C:\git\27844-2-StyleCop\company\Project1\Project1\bin\Debug\Project1.dll
18>  Running Code Analysis...
18>  Code Analysis Complete -- 0 error(s), 0 warning(s)

Clearly there's 3 warnings there being picked up by a combination of the built-in C# DotNetAnalyzers and version 1.0.2 of the StyleCop.Analyzers. What I'm wondering is why the:

18> Code Analysis Complete - 0 error(s), 0 warning(s)

section is not:

18> Code Analysis Complete - 0 error(s), 3 warning(s)

and why none of these warnings (or errors for that matter, as I've seen this happen with rules treated as errors) are appearing in the code analysis log file, Project1.dll.CodeAnalysisLog.xml

I've tried:

  • Turning off/on Enable Code Analysis on Build in the project properties
  • Turning off/on Treat Warnings as Errors in the project properties
  • Ensuring there's no Suppress warnings in the project properties
  • Ensuring that the ruleset I'm using is running on the Configuration / Platform I'm build on
  • Cleaning / Rebuilding
  • Running Code Analysis explicitly on the project

Am I doing something wrong?


Solution

  • Build and Code Analysis are separate steps.

    StyleCop Analyzers do not run in the Code Analysis step (as per https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2456 ).