Upload
nick-harrison
View
1.421
Download
1
Tags:
Embed Size (px)
Citation preview
Introducing FxCopIntroducing FxCopPractical Help for Code Reviews
BackgroundBackground
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
AgendaAgenda
The need for Code ValidationUsing FxCopInterpreting the ResultsReviewing the Existing RulesCreating RulesFitting FxCop into the Life Cycle
Why Code ValidationWhy Code Validation
Ensure adherence to standardsEnsure consistencyEnsure following “Best Practices”Give guidance to new team membersAutomate Code Reviews
Coding StandardsCoding 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
Using FxCopUsing FxCop
Start the UtilitySelect Assemblies to validateAdd custom rules if you have themAnalyze Review the resultsExclude Rules as AppropriateMake Code Changes as AppropriateSave the FxCop Project
Interpreting the ResultsInterpreting 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
The Standard RulesThe Standard Rules
Design Rules Globalization Rules Interoperability Rules Mobility Rules Naming Rules Performance Rules Portability Rules Security Rules Usage Rules
Creating Your Own RulesCreating Your Own Rules
Introspection SDK is not documented!Use Reflector to review existing rulesFind an existing rule that does something
similarStart with the existing rule and understand
how it worksMold it to your needs
Fitting FxCop Into Your Life CycleFitting FxCop Into Your Life Cycle
FxCopCmd is command line utilityAdd FxCopCmd as an External ToolOutput is sent to the “Output” windowRun FxCop without leaving the IDEReview the output with each build
Adding FxCop as an External ToolAdding FxCop as an External Tool
Using FxCop ReportsUsing 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
SummarySummary
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
Where to Get More InformationWhere 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!