Installation and configuration for FxCop tool



Today I am going to explain about the installation and configuration of the fxcop tool.

Description about tool: FxCop is a tool that performs static code analysis of .NET code. It provides hundreds of rules that perform various types of analysis.

  • Design
  • Globalization
  • Interoperability
  • Maintainability
  • Mobility
  • Naming
  • Performance
  • Portability
  • Reliability
  • Security
  • Usage

The following are the steps for installation and configuration of the FxCop tool:
  1. Download FxCop from Microsoft site.
  2. Double-click on FxCopSetup.exe and install it on your system. (It will get installed to the location C:\Program Files (x86)\Microsoft FxCop 1.36)
  3. Once installation is done, run the FxCop tool.

    FxCop1.gif
  4. Create a directory named "FxCop" on "D:" drive.

    Unzip "Sharepoint.zip" to this folder (D:\FxCop). This folder contains the required dll for the project. You can also copy the required dll from the {SharePoint Root}/ISAPI folder.
  5. After opening FxCop tool.

    Create a new project

    FxCop2.gif
  6. Click on "Save Project As" from menu.

    FxCop3.gif
  7. Name it "portal" in the save as dialog.

    FxCop4.gif
  8. After creating portal add target assemblies to it.

    FxCop5.gif
  9. Find the location of your project dll from Visual Studio.

    Path :- <Local Path>\<Your project Name>\bin\Debug
    Note: - Here we are adding these two dynamic link libraries as we have to analyse those with FxCop. In the same way we can add any dynamic link library to this for analysis.

    Add whatever dll that you want to do code analysis for, such as "xyz.dll"
  10. Select the component that you want to analyze by selecting it in tree view.

    Please refer to screen dump below:

    Here we are analysing only the "ButtonCounter" class form Webcontrol.dll.

    FxCop6.gif
  11. Select Rules in "FXCop".

    First select "Rule tab" then only select highlighted rules from the "Naming Rules" section.

    The following rules should be selected for this sample:
    • Identifiers should be cased correctly.
    • Identifiers should be spelled correctly.
    • Identifiers should not contain underscores.

      FxCop7.gif



  12. After the rules selection, click the "Analyze" button in the toolbar.

    Please refer to screen dump below.

    FxCop8.gif
  13. A popup will appear for the user to specify the location of the SharePoint dynamic link library (DLL). Here select the path of "D:\Fxcop" where we have unzipped all SharePoint assemblies. This popup might appear for three or four times for different SharePoint assemblies.

    FxCop9.gif
  14. If any issues are found in code analysis then those will be added in the right side pane of "FxCop".

    FxCop10.gif
  15. To see the details of a issue, click on it. The details will get highlighted as shown in the pane below.

    Here you will get the location of issue.

    FxCop11.gif
  16. Please go to Visual Studio and fix the issue in a given file and rebuild that assembly.

    After successful rebuild again go to FxCop and analyse it or press "F5". The issues that have been fixed will be removed from the issues pane. In this way a developer has to resolve all issues from his\her code.


Hope you like this article. For the developer this tool is very important and it's good if you want to deliver good quality code to reduce maintenance effort or future issues.