FxCop is a tool that analyzes code to validate that it complies with coding standards and detects defects. It includes many predefined rules and allows custom rules to be created. FxCop fits into the development lifecycle by allowing automated code reviews through command line integration or integration into the IDE. Custom reports can also be generated from FxCop results.
2. Background FxCop is used to analyze code based on the generated assembly regardless of the language Automate validation of established standards Create rules to validate custom standards and guidelines
3. Agenda The need for Code Validation Using FxCop Interpreting the Results Reviewing the Existing Rules Creating Rules Fitting FxCop into the Life Cycle
4. Why Code Validation Ensure adherence to standards Ensure consistency Ensure following Best Practices Give guidance to new team members Automate Code Reviews
5. Coding Standards There are established standards for Class Library Developers http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconnetframeworkdesignguidelines.asp These guidelines are implemented as pre built rules for FxCop You can build rules for your own standards
6. Using FxCop Start the Utility Select Assemblies to validate Add custom rules if you have them Analyze Review the results Exclude Rules as Appropriate Make Code Changes as Appropriate Save the FxCop Project
7. Interpreting the Results Add the New Column to track whether an issue is new or not Navigate through the Targets to find only the violations by type, method, property, etc Navigate through the Rules to find only the violations for that rule Jump to Source to have FxCop try to find the source code
9. Creating Your Own Rules Introspection SDK is not documented! Use Reflector to review existing rules Find an existing rule that does something similar Start with the existing rule and understand how it works Mold it to your needs
10. Fitting FxCop Into Your Life Cycle FxCopCmd is command line utility Add FxCopCmd as an External Tool Output is sent to the Output window Run FxCop without leaving the IDE Review the output with each build
12. Using FxCop Reports Specify a Style Sheet for the Report Save Report As from the File Menu View the resulting XML file. May need to save it as HTML Write your own XSLT to change the format Include the report with migration requests Include the report with Code Reviews Include the report with project documentation
13. Summary FxCop is used to automate the code review process FxCop includes rules for detecting over 200 different defects You can create your own rules to validate your own standards FxCop easily fits into your development life cycle
14. Where to Get More Information http://aspnet.4guysfromrolla.com/articles/060204-1.aspx http://www.futureware.biz/blog/index.php?title=writing_your_own_fxcop_rules_library http://msdn.microsoft.com/msdnmag/issues/04/09/Bugslayer/ http://www.biasecurities.com/blogs/jim/archive/2004/12/29/818.aspx http://www.gotdotnet.com/team/fxcop/ http://blogs.msdn.com/fxcop/archive/2004/01/09/49287.aspx http://www.gotdotnet.com/team/fxcop/docs/UsingFxCop.htm http://www.geekswithblogs.net/nharrison http://www.aisto.com/roeder/dotnet/ Reflector!