This project is read-only.

Debugging custom rules dll

Aug 4, 2010 at 11:10 AM

1. What is the best way to debug my Custom Rule set dll?

2. StyleCopLogLevel: why is it documented  inadequately (or is it just me ?)

I mean it is not clear when to use which level, or how this can be configured...

I have code like

Log(StyleCopLevel.High, "SomeMessage")

in the place that I know is getting hit...But the message is not displayed in output window...

3. I simply want a Negate SA1200, which "Validates that all using directives are placed within a namespace, if a namespace exists in the file. 

My code look like this: ( btw, I am not familiar with the object model, what is the best way to play with it?)
if (element.ElementType == ElementType.UsingDirective)
{ if (parentElement.ElementType == ElementType.Namespace)
{ AddViolation(element, "NamespaceOutside"); } }

Many Thanks,,


Aug 4, 2010 at 4:17 PM

1. The simplest way to debug is to install StyleCop, drop a debug build of you ryour custom rules DLL and PDB into a folder where StyleCop will pick it up, run one instance of VS to act as your debugger, then run another instance of VS to act as your debug target. In the first instance of VS, select Debug->Attach to Process, and attach to the second VS instance. Now you can set breakpoints, etc.

2. StyleCopLogLevel is not currently used, hence the no documentation thing.

3. Looks ok to me.


Aug 4, 2010 at 8:42 PM

Debugging worked.. (and the rule)

But there is something fishy that I still cannot figure out;  About the timing when the custom dll gets picked up.. ( I had disabled caching in the project)
MyCustomRule dll is in use even when the project is loaded But no StyleCop is run yet..
On one instance it started working only after I explicitly debugged into it.
Yesterday I had set Debugger.Break() but that did not work..

Btw, it is painful to close both the VS entirely during development, any other trick that I could use?

Aug 5, 2010 at 3:14 PM
You could use unit testing to debug your rule. Take a look at Just add your rules project to the solution and add a reference to your project from StyleCopContrib.CustomRules.Tests and you will be able to write unit test to validate your rules.
Apr 30, 2013 at 8:50 PM
The debug method, as it was posted by jasonall, works. To debug again on the same session, you have to use the "Rescan All" option