How to debug custom code analysis rules?

I wrote some custom rules in C #, following the step-by-step instructions that I found on this site . When I try to do code analysis in visual-studio-2013 , I get error CA0054 in the CA results pane.

I would like to debug my rule as an exception is explicitly thrown from it. However, I cannot figure out how to do this. I tried connecting a new instance of Visual Studio to another running instance, but it does not work.

There are many resources on the Internet for debugging user rules, but they are all for the old version of FxCop, with a separate graphical interface and everything else. I do not think this is relevant to my case.

Did I miss something?

+7
c # visual-studio code-analysis
source share
1 answer

I found my answer here:

How to write your own rules for analyzing static code and integrate them in Visual Studio 2010

You can debug custom rules through FxCopCmd.exe. Usually you will follow your rule against another project. To simplify the instructions, this blog was about to launch our new rule against implementing the rule itself. In the project properties for your custom project rules, on the Debug tab

  • Configure the project to run an external program and enter the path to the FxCopCmd.exe file. For example, C: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ Command Instruments \ Static Analysis Tools \ FxCop \ FxCopCmd.exe

  • For command line arguments, specify / out: "results.xml" / file: "MyCustomRules.dll" / rule: "MyCustomRules.dll" / D: "C: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ Command Tools \ Static Analysis Tools \ FxCop "

  • Set the working directory to the output folder of the assembly. For example, C: \ Projects \ MyCustomRules \ MyCustomRules \ bin \ Debug \

Now you can debug your custom rules by simply pressing F5 from your custom rules project. Try

+2
source share

All Articles