FAQ: How do I debug a custom rule?
While writing your custom rule, you will likely come across a need to debug it and work out why it's behaving in a particular manner.
Debugging within FxCop
Debugging a custom rule within the FxCop UI is actually quite easy. To do so, simply:
- Open the FxCop project that contains your custom rule (making sure the PDB is alongside the assembly)
- Open the solution that contains your custom rule and set a breakpoint in the rule your want to debug
- Choose Debug -> Attach to Process
- Under Available Processes, choose FxCop.exe and click Attach
- In FxCop, choose Project -> Analyze
The debugger should break when it hits the breakpoint.
Debugging within Visual Studio or via command-line
However, if you want debug a rule that you've written for Visual Studio Code Analysis, or via the command-line, the procedure is not so obvious:
Open a Visual Studio Command Prompt
If debugging a custom rule written for Visual Studio, run the following:
> cd %VSINSTALLDIR%\Team Tools\Static Analysis Tools\FxCop
Otherwise, if debugging a custom rule written for FxCop, run the following:
> cd %PROGRAMFILES%\Microsoft FxCop 1.35
Run the following command, replacing [TargetAssembly] and [RuleAssembly] with the assembly you want to analyze and the assembly that contains your custom rule respectively.
> devenv /debugexe FxCopCmd.exe /file: [TargetAssembly] /rule: [RuleAssembly] /console
This will open Visual Studio in a state that is ready to debug your custom rule.
Choose File -> Open -> File and browse to and open the source file that contains your custom rule
Set a breakpoint in the rule
Choose Debug -> Start Debugging
The debugger should break when it hits the breakpoint.
The Modules window is your friend
If the breakpoint is not being hit, check to make sure that you actually have symbols for your custom rule loaded:
While debugging, choose Debug -> Windows -> Modules
To do this if you are debugging via /debugexe switch, as soon as the command window opens to start running FxCop, click PAUSE on the keyboard .
Look for your rule assembly and check under the Symbol Status column.
If this column states anything other Symbols Loaded, then right-click on the assembly and choose Load Symbols and browse manually to the PDB.
Comments
Anonymous
June 27, 2007
I'd also like to reocmmend FxCop unit to help: http://weblogs.asp.net/rosherove/archive/2007/02/24/introducing-fxcopunit-a-framework-for-integrated-fxcop-rule-testing.aspxAnonymous
November 25, 2007
In previous posts about Code Metrics and Code Reviews , I explored some metrics and techniques that IAnonymous
December 20, 2007
In previous posts about Code Metrics and Code Reviews , I explored some metrics and techniques that I