Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I supress static code analysis during build?

We have a solution with 15 projects, which all has code analysis enabled.

The solution easily takes 60+ seconds to build, which is a very long time when sitting waiting.

If I disable code analysis it builds in 10 sesonds.

I would love to be able to disable code analysis on an ad-hoc basis. But still I want code analysis when building before check-in, and also I want our Build Server (Cruise Control) to continue running with Code analysis enabled.

I'd prefer if code analysis is running from within Visual Studio, so I can jump directly to the source code if I get an error/warning.

like image 550
Thomas Jespersen Avatar asked Dec 30 '22 17:12

Thomas Jespersen


2 Answers

Here's how we do it:

  • Disable (or rather: do not enable) Code Analysis (CA) for Debug builds.
  • Create a new Build Configuration called Verify where Code Analysis is enabled, and warnings are treated as errors.
  • Keep Release build as is.

We do our normal development in Debug mode, and simply have an informal rule that you must pass a Verify build before you check in.

This is easy to forget, but we run Continuous Integration (CI) on the Verify build, so if you check in code that has Code Analysis warnings, you break the build - so people quickly learn to do a manual Verify build before checking in :)

You can also just use Debug without CA and Release with CA, but since enabling CA defines the CODE_ANALYSIS constant, it means that CA Suppressions will be included in the IL, and I prefer not having that in my Release binaries (YMMV).

like image 188
Mark Seemann Avatar answered Jan 10 '23 01:01

Mark Seemann


We had that sort of problem with our stuff. We just got everyone quad 64bit processors and between 8 an 16GB ram. Plus we tried to limit the number of projects at any one point. Not the most graceful solution but it helped a lot.

like image 22
Robin Vessey Avatar answered Jan 10 '23 02:01

Robin Vessey