TL;DR: It is possible to disable the Static Analysis phase in VS2012 projects by setting the DevDivCodeAnalysisRunType environment variable to “Disabled”.

 

This will be a quick post, but which might save you a lot of time if you rely heavily on Code Analysis (FxCop).

FxCop is definitely not known for its analysis speed, and when ran in every build, this takes a lot of time. I usually work on projects where FxCop is only enabled in the Release Configuration, which helps during development in Debug configuration.

But if you’re bound to run in Release configuration, such as when profiling the app, or any other task that requires to build in that configuration, then having FxCop running every single time can be time consuming.

To avoid this, there are multiple choices :

  • Use find and replace to change <RunCodeAnalysis>true</RunCodeAnalysis> to <RunCodeAnalysis>false</RunCodeAnalysis>, but then you have to remember to not check that into your source control (even if the Perform Code Analysis setting is set to Always in your CI Build definition),
  • Create an alternate configuration similar to Release that does not have the Static Code Analysis enabled, but changing configurations in VS2012 can take time (even with the Update 2) and you’ll have to maintain that configuration with the others,
  • Or you can use a little trick to disable the static code analysis for a whole Visual Studio instance.

 

That trick is a bit hidden, but here’s how you can do this :

  • Open a Developer Command Prompt for VS2012
  • type set DevDivCodeAnalysisRunType=Disabled
  • type devenv

 

Build your solution and you won’t have the static analysis running, without any modification to your solutions’ configuration or projects. Easy.

That said, remember that this is not documented and might change at any point in the future so don't rely on it too much.