Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Code Analysis from rebuilding project and dependencies in Visual Studio 2012

After upgrading our solution to Visual Studio 2012 we are looking to take advantage of the new Code Analysis feature. However, it is taking too long to run, because it is rebuilding the project and dependant projects before it runs, even though the code has not changed and does not need a rebuild.

Is there a way to stop it rebuilding code if a rebuild is not required?

like image 224
user2732185 Avatar asked Aug 30 '13 08:08

user2732185


People also ask

How do I disable code analysis in Visual Studio?

To open this page, right-click the project node in Solution Explorer and select Properties. Select the Code Analysis tab. To disable source analysis at build time, uncheck the Run on build option. To disable live source analysis, uncheck the Run on live analysis option.

Why is Visual Studio rebuilding every time?

Sometimes, Visual Studio will always rebuild projects, even though they have recently been built and there are no changes. If you build , and then run the project will build. If you haven't disabled the “projects out of date”-dialog, it will pop up and ask you to rebuild.

What is difference between build and rebuild in Visual Studio?

Build and rebuild are two options available in Visual Studio. The main difference between build and rebuild in Visual Studio is that build helps to complete the code files which are changed while rebuild deletes all previously compiled files and compiles the solution from scratch ignoring anything done before.


2 Answers

I believe Johns statement above to be incorrect.

In my experience, the projects always get rebuilt regardless of whether they are configured for code analysis or not.

I have a solution with over 100 projects. if I select 1 project and run code analysis on that project only, it rebuilds that project and all projects it is dependant on. It doesn't run code analysis on the other projects, but it still rebuilds them.

So why does it have to rebuild all the child projects to run code analysis?

like image 160
LarryB Avatar answered Oct 27 '22 17:10

LarryB


If you are just starting to use code analysis, then you may be mistaking the symptoms. You are seeing: e 1. Code analysis takes a substantial amount of time, and 2. During code analysis, the project builds

You may be combining these two symptoms and reaching the conclusion that code analysis is forcing a rebuild of your project. This would be a false assumption. Try this:

  1. Ensure that your projects are configured to not run code analysis upon build
  2. Rebuild your solution. Note how long it takes
  3. Build (don't rebuild) your solution, but this time, note how long it takes

You will find that your solution actually "builds", but since the projects are up to date, the compilers and other tools do not run.

So, it's true that code analysis runs a build of your solution first, but it will be a build like #3 above - nothing has changed, so the tools won't run. Only the code analysis tool (FxCop) will run. This takes longer than you might expect, but it's worth it.

In our environment, I created a "Local" solution and project configuration, copied from "Debug". This configuration is mostly the same as "Debug", but does not run code analysis. This is what our developers use on a day to day basis. When code is checked into TFS, it starts a Continuous Integration (CI) build in the "Local" configuration, again, without code analysis.

On the other hand, the nightly build runs the "Debug" configuration, so it does run code analysis. I find that we don't need the results of a code analysis on every build, but it's damned well necessary once a day.

OBTW, Code Analysis is not new. If you look at that MSDN page you linked to, you'll find a 2010 version of the page in the "Other versions" dropdown. In fact, the code analysis feature was available as a Visual Studio add-in called "FxCop", before it became part of the product.

like image 40
John Saunders Avatar answered Oct 27 '22 17:10

John Saunders