StyleCop Custom Rules

Posted by Aligned on Geeks with Blogs See other posts from Geeks with Blogs or by Aligned
Published on Wed, 26 Sep 2012 12:51:53 GMT Indexed on 2012/09/26 21:38 UTC
Read the original article Hit count: 257

Filed under:

There are several blogs on how to do this (http://scottwhite.blogspot.com/2008/11/creating-custom-stylecop-rules-in-c.html, etc). I’ve found a few useful things to point out:

  • Debugging is difficult, but here are the steps (thanks to Tintin’s answer).

    “One way:

    1) Delete your custom rules
    2) Open Visual Studio (for dev), open your custom rule solution
    3) Build & Deploy custom rules (a PostBuild action to copy the rules into the StyleCop folder is handy)
    4) Open Visual Studio (for test)
    5) Use VS (dev) and Attach to process devenv.exe (the test VS instance), set breakpoints in the rules you want to debug
    6) Use VS’ (test) and right-click on project, Run StyleCop
    7) Debug”
    ~ it worked once, now I’m having problems getting it to work again
    ~ I also get the message “Cannot evaluate expression because the code of the current method is optimized.” when I try to look at properties.

  • Looking at the source code of the StyleCop.CSharp.Rules.dll that comes with the install. I used JustDecompile from Telerik.

  • Create one xml file and name it the same as the one cs file (CodingGuildelineRules.cs and CodingGuidelinRules.xml)
  • Deploy:
    1. Build in Visual Studio
    2. Close Visual Studio (Style cop is running so you can’t override your dll without closing)
    3. Copy the dll from the bin to the C: \Program Files (x86)\StyleCop 4.7\
    4. Open the settings file or re-open Visual Studio

© Geeks with Blogs or respective owner