Naveen's Weblog

Bridge to future

Writing Custom FxCop Rules

Posted by codingsense on May 23, 2010


FxCop is a static analysis tool that you can use to write custom rules those need to be followed by the developers. Writing custom rules in FxCop is very easy, in the beginning you will feel it bit complex since there are no much help available on web but once if you have written a rule you will be preety much confident that you can write any rule you desire.

Download FxCop

SInce FxCop analyses IL code from your assemblies, we should know about some of the keywords of IL to write complex rules. Use this sheet as a reference while seeing your IL code through ILDASM.

I have created a template project for Custom FxCop Rules for you which you can use and add your rules. So that you can concentrate more on Custom Rules rather than creating the project.

Download CustomFxCopRules template

If you want to add any new rule you have to follow these steps using the above template.

  1. Create a class and name it with the rule.
  2. Create a new node of that of the classname (not necessary but only for easier reference) in CustomRules.xml with desired settings
  3. Create a constant with the same name and value in Constants.resx file
  4. Write your logic in that class

And to debug the rules that you have written here is a post
http://social.msdn.microsoft.com/forums/en-US/vstscode/thread/b92a0416-bf20-40c1-88a0-8fcff07133dc/

More References:
http://www.binarycoder.net/fxcop/pdf/fxcop.pdfhttp://www.binarycoder.net/fxcop/pdf/fxcop.pdf
http://www.nmentor.com/Blog/Tutorials/1.%20How%20to%20Write%20Custom%20FxCop%20Rule.pdf

I will put some of the custom rules in coming post which willl cover all the required topics to make you understand FxCop better. If you want any specific rule, then feel free to post a comment to me and I will help you out 🙂

Happy Learning
Codingsense 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: