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

More References:

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 🙂


Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: