Custom rules worked till I downloaded 4.6

Dec 15, 2011 at 9:17 PM

I had a custom rule that was working with StyleCop 4.3. I added a couple more rules and they worked as well. I upgraded to 4.6, copied my DLL to the Program Files (x86)\StyleCop 4.6 folder, and can no longer see my custom rules in the settings editor. How can I get my code working again (without reverting to the old StyleCop)?

Dec 16, 2011 at 7:16 PM


Have you rebuilt you custom rules with StyleCop 4.6 binaries?

Best regards,
Oleg Shuruev

Jan 24, 2012 at 6:40 PM
Edited Jan 24, 2012 at 6:44 PM

Same issue here. I'm using 4.7.6 and am referencing those binaries in my project. Does not show up in the editor when I copy it to the StyleCop folder. My project is a class library. Code is below. Using C# 4



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StyleCop;
using StyleCop.CSharp;

namespace CI.StyleCopRules
    public class InstanceVariablesUnderscorePrefix : SourceAnalyzer
        /// <summary>
        /// This StyleCop Rule makes sure that instance variables are prefixed with an underscore.
        /// </summary>
        public override void AnalyzeDocument(CodeDocument document)
            CsDocument csdocument = (CsDocument)document;
            if (csdocument.RootElement != null && !csdocument.RootElement.Generated)
                csdocument.WalkDocument(new CodeWalkerElementVisitor<object>(this.VisitElement), null, null);

        private bool VisitElement(CsElement element, CsElement parentElement, object context)
            // Flag a violation if the instance variables are not prefixed with an underscore.
            if (!element.Generated && element.ElementType == ElementType.Field && element.ActualAccess != AccessModifierType.Public &&
                element.ActualAccess != AccessModifierType.Internal && element.Declaration.Name.ToCharArray()[0] != '_')
                AddViolation(element, "InstanceVariablesUnderscorePrefix");
            return true;




<?xml version="1.0" encoding="utf-8" ?>
<SourceAnalyzer Name="Extensions">
    These custom rules provide extensions to the ones provided with StyleCop.
    <Rule Name="InstanceVariablesUnderscorePrefix" CheckId="EX1001">
      <Context>Instance variables should be prefixed by underscore.</Context>
      <Description>Instance variables are easier to distinguish when prefixed with an underscore.</Description>
Jan 24, 2012 at 6:49 PM

Figured it out. Changed my project to .net 3.5 and renamed the xml filename to be the same as the class name.