This project is read-only.

StyleCop 4.7.17 Custom Rules

Apr 3, 2012 at 9:00 AM

Hi all !

I have some problem to get Microsoft StyleCop to pick a new rule up. The new rule is not shown in the Settings.

I just did as said in the documentation _StyleCopSDK.htm

The assembly is compiled without errors.

AccessModifiers.cs and AccessModifiers.xml below

I'm using VS10 with SP1 and SC 4.7.17

Thanks for help in advance


namespace AccessModifiers
    // Checks for the presence of access modifiers on all elements.
    public class AccessModifiers : SourceAnalyzer
        public override void AnalyzeDocument(CodeDocument document)
            CsDocument csdocument = (CsDocument)document;
            if (csdocument.RootElement != null && !csdocument.RootElement.Generated)
                    new CodeWalkerElementVisitor<object>(this.VisitElement),

        private bool VisitElement(CsElement element, CsElement parentElement, object context)
            // Make sure this element is not generated.
            if (!element.Generated)
                // Flag a violation if the element does not have an access modifier.
                if (!element.Declaration.AccessModifier)
                    this.AddViolation(element, "AccessModifiersMustBeDeclared");
            return true;





<?xml version="1.0" encoding="utf-8" ?>
<SourceAnalyzer Name="Extension">
    This is my first rule ever done.
    <RuleGroup Name="MLOYRules">
      <Rule Name="AccessModifiers" CheckId="MY1000">
        <Context>What ever it is !!.</Context>
        <Description>Detail descrition.</Description>

Apr 3, 2012 at 9:56 AM

Hi all !

There is a really good instruction of how to make custom rules done by shuruev :

Unfortunately I found that it works fine with .NET3.5 but not with 4.0. Actually the rule works fine with both, but

only with .NET3.5 the rule is visible in settings form.

If someone can confirm my findings it would be quite useful.



Apr 4, 2012 at 7:10 AM

Hey savirpe,

I think that is true while StyleCop is wirtten using .NET 3.5.

Best regards,
Oleg Shuruev