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?
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
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
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"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With