Tuesday, June 14, 2011

FxCop Tutorial

FxCop is a tool provided by Microsoft that manages code assemblies. It check possible designs, localization, performance and security improvements.
It’s a tool that performs static code analysis of .Net code. Analysis like Design, Globalization, Interoperability, Maintainability, Mobility, Naming, Performance, Portability, Reliability, Security, Usage
It is basically meant for class library projects and if you have followed the standards provided here http://go.microsoft.com/fwlink/?LinkId=70287 by Microsoft, then you will get more benefit from it.
It has an graphical user interface (FxCop.exe) for interactive work, and a command-line tool (FxCopCmd.exe)  suited for use as part of automated build processes or integrated with Microsoft Visual Studio® .NET as an external tool.
It also show messages sometime how to solve the issue.
FxCop has some rules inbuilt but you can also additional rules by using FxCop SDK. Through Projects are used to specify the set of assemblies you want to analyze, the rules that are used to analyze the assemblies, the excluded messages, and the settings to customize the saved project or report file.
Visual Studio is fully Integrated for FxCop, you can check from the below URL. http://www.microsoft.com/downloads/en/details.aspx?FamilyID=917023f6-d5b7-41bb-bbc0-411a7d66cf3c
But for previous versions of Visual Studio you have to go to the below path and run the set up.
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\FXCop
Remember I have Windows 7 64bit installed in my laptop and I have both VS 2005 and VS 2010. Please change the path according to your OS installation.
After installation it will appear under program files in the start menu.
To work with it got to Start -> All Programs -> Microsoft FxCop then Click on Microsoft FxCop [Version Number]. Once you will click on this a window will appear as shown below.

 Then go to project from the menu bar then click on Add Targets… It will ask you to give the path of your .dll or .exe path. Once you will add, your project will successfully loaded. Then you can click on Analyze button. The result will come as shown below.

And If you click on a particular error message it will show you the details as shown below figure.

If you want to see more details messages except the above then select one message and click Enter or simply double click on the message. A window with the detailed message will appear as shown below.
You can select/deSelect the Rules by check/UnCheck the check boxes presented the Rules Tab as shown in the below figure.

If Analysis causes any error then the Analysis Summery dialog box will open or anytime you can also open the Analysis Summery dialog box by going Project ->Analysis Summery. It will look like the figure below.

In Visual Studio 2010 If you want to use Code Analysis in Visual Studio 2010, then you can directly go to the Analyze Menu and then Click on Run Code Analysis on [Project Name], that will look like the figure below.


No comments:

Post a Comment