In yesteryears lots of time was spent on reviewing code & analysing it. Despite this desired result was not guaranteed. Developer's and reviewer's job became easy when Microsoft introduced automatic tools for code analysis. These utilities cover all aspects of code analysis & review.
We feel that logical code review can only be done by people who know requirements very well of the proposed system in development. Currently reviewers just need to focus on logical review with respect to requirements of the application. As other aspects of code review and analysis can be done with the help of 'Code Analysis' feature of Visual Studio.
The feature is available in Visual Studio 2012 or above, VS 2010 Premium and VS 2010 Ultimate editions.
The Visual Studio Code Analysis feature helps developers to find out performance, security, designing, exception management, globalization & other problems to improve the Code Quality. Code Analysis can be performed on a complete solution or a specific project in the solution.
To perform Code Analysis, open your solution in VS 2012, expand ANALYZE tab on the menu bar & select Run Code Analysis on Solution as shown below.
We would see a new 'Code Analysis' tab adjacent to 'Solution Explorer' tab (see below).
In this example we can see two records (Errors + Warnings) in the window with the same code (CA2214) in two separate files (Employee.cs & Trip.cs). Resultant list can be further filtered by searching keywords in 'Search' text box.
In order to see the detail, just select the Message, it would expand itself & also highlight the piece of code against which this warning is generated. For each message a developer can take certain actions (Copy, Create a Work Item, Suppress Message) by Right Click or by pressing the Action link.
To Configure Code Analysis for a specific project or for the complete solution, Right Click on the selected project or solution, select Properties & then select Code Analysis. In this window developer can set Configurations (Debug, Release, All) & Platform (Any CPU, X64 etc.) settings and can also select a Rule Set or Multiple Rules Sets for the Code Analysis from default rule set list as shown below. By default 'Microsoft Managed Recommended Rules' is selected.
To select multiple rule sets click on optionÂ <Choose multiple rule sets..>
Similarly further configurations can be done by selecting only specific categories and Ids within a rule set and saving it as new rule set. Moreover rules severity can be set to 'Error', 'Warning', 'None' or 'Inherit' by changing its action. Press 'Open' button next to Rule Set drop down control to configure rules.
Code Analysis can not only be done manually using 'Run Code Analysis', it can be run automatically on each build. To run the code analysis automatically while building the source code, check the 'Enable Code Analysis on Build' option on the code analysis window (Figure - Code Analysis Settings).
The useful features of 'Code Analysis' have become very useful for developers.
For complete details of every code analysis warning please visithttp://msdn.microsoft.com/en-us/library/ee1hzekz(v=vs.100).aspx