• January 2018 (2)
  • December 2017 (1)
  • November 2017 (2)
  • October 2017 (3)
  • September 2017 (4)
  • August 2017 (3)
  • July 2017 (3)
  • June 2017 (3)
  • May 2017 (1)
  • February 2015 (2)
  • January 2015 (1)
  • December 2014 (3)
  • February 2014 (2)
Tags View All Blogs
Scrum.NetMicrosoftVisual StudioVC++C#JavaTestingQuality AssuranceUX DesignSPAAngularKnockoutBackboneUnderscoreDatabaseMySQLBlockchainHyperledgerChaincodeEnterprise MobilityUIIonicCordovaHybrid AppCode ReviewTypescriptAndroidIOTReactICOVenture CapitalArtificial IntelligenceKotlinIoTFuchsia OSVirtual RealityVOIPCrowdfunding Testing

Visual Studio Code Analysis: A handy tool for developers

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.

Visual Studio menu bar Analyze Tab

We would see a new 'Code Analysis' tab adjacent to 'Solution Explorer' tab (see below).

Code Analysis Tab

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.

Code Analysis Tab messages

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.

Code Analysis Configurations

To select multiple rule sets click on optionĂ‚  <Choose multiple rule sets..> and click on Save As button to give this set a specific name and the same rule set would be visible in the dropdown above.

Code Analysis Configuration Multiple Rule Sets Selection

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 Configuration Categories

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 visit