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?
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.
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.
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.
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?
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With