Visual Studio Code Analysis is an integrated tool in Visual Studio which can be used for code reviewing the managed code assemblies. It can analyze managed code and gives reports on various improvements needed for the code such as possible design, localization, performance, and security improvements.
The advantage of using Code Analysis in Visual Studio over FxCop standalone application is that code analysis settings are inbuilt in the project properties and can be set and checked in to any source code version control software. So that everyone in the development can use the same settings.
The code analysis option is available in Premium and Ultimate editions of Visual Studio 2010 & 2012 and also in Visual Studio 2005 & 2008 Team System.
Steps to enable code analysis option:
- In the Visual Studio solution, select a project and right click.
- In the right click menu select properties.
- In the properties window go to Code Analysis tab.
- In the code analysis tab enable the rules which need to be analyzed.
- Select the treat warning as errors corresponding to the selected rules so that the code analysis findings can be segregated from the regular warnings.
- Save the project.
- Do the above steps in all the projects in the solution
- Right click the project and select Run Code Analysis. This will build the project and lists the code review issues as errors.
- This won’t affect the normal build process. The code analysis will be done only when we run code analysis.
- But in case if we need to do the code review on every compilation and throw the review issues as errors, then select the Enable Code Analysis on Build option in the project properties code analysis tab. This option will provide a tight integration and automation of code review, by throwing error in any selected code analysis rule violation.