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!
2
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:
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:
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:
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:
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.
Not entirely sure about the "Run background code analysis for" option, but I’m assuming it runs Roslyn code analysers (if you use these) in the background, rather than just on build.
From what I’ve experienced of the "Show compiler errors and warnings for", it seems to be a bit like a "live errors" window, showing build errors as you type, without actually having to build the solution.
E.g. if you make a breaking change to some code then you’ll see the resulting errors start to populate in this window from across the solution (assuming you’ve selected the "entire solution" option). It can be quite slow and can take quite a bit of time for the b/g process to find and display the errors in the window. I guess this depends on solution size and PC performance.