Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I debug Code Analysis custom rules?

I wrote some custom rules in C#, following the step-by-step instructions I've found on this site. When I try to run Code Analysis in visual-studio-2013, I get a CA0054 error in the CA result pane.

I would like to debug my rule, as the exception obviously is thrown from it. However, I can't figure out how to do that. I tried to attach a new instance of Visual Studio to the other running instance, but it doesn't work.

There are lots of resources on the web on debugging custom rules but they're all for the old version of FxCop, with the separate GUI and everything. I don't think that it's relevant to my case.

Am I missing something here?

like image 986
Crono Avatar asked Aug 28 '14 12:08

Crono


1 Answers

I've found my answer here:

How to write custom static code analysis rules and integrate them into Visual Studio 2010

You can debug custom rules through FxCopCmd.exe. Normally you would run your rule against another project. To simplify the instructions in this blog we’re going to run our new rule against the implementation of the rule itself. In the project properties for your custom rules project on the Debug tab do the following

  1. Configure the project to launch an external program and enter in the path to FxCopCmd.exe. For example C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe

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

  3. Set the working directory to the build output folder. For example C:\Projects\MyCustomRules\MyCustomRules\bin\Debug\

Now you can to debug your custom rules by simply hitting F5 from your custom rules project. Try it

like image 140
Crono Avatar answered Oct 14 '22 11:10

Crono