Thursday, February 03, 2011

Code Analysis using VS.Net 2010

The Code Analysis tool is available as part of Visual Studio. When we enable code analysis, our code is validated against the rule defined in Microsft FxCop (current version is 1.36). FxCop is a free code analysis tool from Microsoft available for a long time and now it is integrated within Visual Studio in the form of Code Analysis option which is available. There are many design rules, coding conventions, security, usage guidelines and localization rules defined in the form of rules and we can run our code through all these rules.

To understand this, lets dig into this. I have created a sample project called SampleCATest which has just one method. When I build this code, I get zero warnings and errors.
Now, under project settings, go to Code Analysis tab.

I am enabling Code Analysis, ignoring code analysis rules for generated code and using Microsoft Minimum recommended rules.

fig2.gif

Read more: C# Corner