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.
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.
If you want to add any new rule you have to follow these steps using the above template.
- Create a class and name it with the rule.
- Create a new node of that of the classname (not necessary but only for easier reference) in CustomRules.xml with desired settings
- Create a constant with the same name and value in Constants.resx file
- Write your logic in that class
And to debug the rules that you have written here is a post
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 🙂