Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The difference between new VS code analysis options "Show compiler errors and warnings for:" and "Run background code analysis for:"

I have just installed the latest update 17.3 for Visual Studio 2022 and noticed that code analysis settings changed. Now there are two options for code analysis scope:

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

Previously in VS version 17.2 there was only one "Run background code analysis for:" option. I didn't manage to find the description of the "Show compiler errors and warnings for:" setting in the release notes: https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes

I also didn't manage to google anything about it in the internet.

I would like to know what the "Show compiler errors and warnings for:" setting does and what is the difference between it and "Run background code analysis for:"

Thanks in advance!

like image 240
SENya Avatar asked Oct 22 '25 00:10

SENya


1 Answers

After some testing and playing with new code analysis settings I feel that I found out what "Show compiler errors and warnings for" and "Run background code analysis for" settings do now. I will post my results as an answer. If you can add more details to my answer please do.

In short, the settings now divide code analysis diagnostics into two groups:

  • Compiler diagnostics. Now you can configure the analysis scope for them with the "Show compiler errors and warnings for:" setting
  • Diagnostics from custom Roslyn code analyzers. Now you can configure the analysis scope for them with the "Run background code analysis for" setting

The scopes are independent of each other. You can configure compiler diagnostics to be collected from the entire solution and custom diagnostic to be collected only from the current document. This way you can get build errors from the wider scope and save performance by running custom analyzers (which may require quite a lot of resources) on a narrower scope.

I tested this behavior by writing code that contains both syntax error and alert from the custom analyzer. To do this I installed xUnit unit test framework and xUnit analyzers provided with it. Then I wrote a simple unit test with syntax error and incorrect usage of xUnit:

The incorrect test

As you can see here, the test is marked with the Fact attribute but it contains parameters. Thus, it is reported by xUnit analyzers. Additionally, there is a syntax error in the parameters list.

My current settings for code analysis are Opened documents for both analysis scopes. When I change "Show compiler errors and warnings for:" setting to None the compiler diagnostic on syntax error disappears:

No compiler error

The alert is displayed again after I change the setting back to Opened documents. And when I change "Run background code analysis for" to None the xUnit analyzer diagnostic disappears: No custom alert

So it seems to me, that now you can just configure code analysis separately for serious compiler checks and custom third party diagnostics.

Still, I would appreciate if someone shared the documentation for these settings with me.

like image 151
SENya Avatar answered Oct 24 '25 15:10

SENya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!