12

The problem is that not all visual studio suggestions, warnings and/or errors are shown on solution build.

Let's say that on solution build, a total of 22 warnings are shown. After solution build, upon opening .cs files within projects, more warnings are being shown.

Steps:

  1. Rebuild solution
  2. Error List shows 0 Errors, 22 Warnings, 0 Suggestions
    • Error List after Build
  3. Open a .cs file from within a .csproj
  4. Error List shows 0 Errors, 22+ Warnings, 0+ Suggestions
    • Error List after opening a couple of .cs files

Why aren't these errors/warnings/suggestions shown on build, rather than being shown once a corresponding .cs file is opened?

Note - An .editorconfig file is used within the solution. This .editorconfig specifies a set of rules which define when to show Errors, Warnings, and Suggestions within .cs files.

Dash
  • 401
  • 5
  • 14
  • Note the combobox that now says "Build + IntelliSense". If you only want to see build diagnostics then change it to "Build". The code analysis warnings you now have show up when you open the file in the editor. Maybe you ought to tame the feature a bit, too many of those warnings do get distracting. – Hans Passant Nov 01 '19 at 09:53

3 Answers3

13

I faced this issue and, for me, what worked was simply following the below steps:

  1. Analyze -> Run code Analysis -> On Solution

Click here for image

This will give all warnings on solution level.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
3

In Visual Studio 2022 I missed many warnings too - via Tools > Options, tab Text Editor > C# > Advanced you find these settings:

  • Run background code analysis for:
  • Show compiler errors and warnings for:

and for both you probably want the option Entire solution (instead of Open documents, Current document or None).

enter image description here

SymboLinker
  • 884
  • 6
  • 15
0

You can enable Source code analysis for a single project through the Project Properties dialog. This will in fact install some NuGet packages into the project, which together will run an analysis on each build of the project.

This is not an exact replica of Intellisense analysis, if only because what it will do depends on the selected Rule Set. For the most part I expect this to be at least as thorough as the Intellisense analysis, and probably even more so.

Here is how to install it, and how to select a Rule Set:

Set up Code Analysis

For more info, see

Peter B
  • 22,460
  • 5
  • 32
  • 69
  • Hi Peter, yes I saw the Code Analysis section of a .csproj but this is not exactly what we want. We want a to configure code analysis per solution instead of per .csproj and whether it is possible to use the .editorconfig as the analyzer instead of the "Recommended analyzer package". – Dash Nov 01 '19 at 06:59
  • .editorconfig is a cross-platform standard for file-extension-based *editing* behaviour such as auto indentation, braces behaviour, spaces vs tabs. It has nothing to do with building code or analyzing it, and I don't think it ever will. – Peter B Nov 01 '19 at 09:41
  • I'm working with a .NET Standard project so the "Code Analysis" tab doesn't appear in the Project Properties window. I have both `Microsoft.CodeAnalysis.CSharp` and `Microsoft.CodeAnalysis.FxCopAnalyzers` NuGet packages installed in my project with `CODE_ANALYSIS` defined - yet only a couple of all of the generated code-analysis warnings appear in the Error List (yes, I reset the filters too and selected "Entire solution"). Weird. – Dai Feb 02 '20 at 08:39