Cant import Custom Rules

Nov 25, 2011 at 1:48 PM

Hi, 

I´ve tried to import my customs rules, but it still don´t work. 

Here are my files "CustomRule.cs" and "CustomRule.xml": 

 

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

namespace CustomStyleCopRule
{
    [SourceAnalyzer(typeof(CsParser),"CustomRule.xml")]
    public class CustomRule : SourceAnalyzer
    {
        public override void AnalyzeDocument(CodeDocument document)
        {
            Param.RequireNotNull(document, "document");
            CsDocument document2 = (CsDocument)document;
            if ((document2.RootElement != null) && !document2.RootElement.Generated)
            {
                AddViolation(document2.RootElement, "MyCustomRule", new object[0]);
            }
        }
    }
}

<?xml version="1.0" encoding="utf-8" ?>
<SourceAnalyzer Name="Custom Rules">
  <Description>
    Custom rules added to analyzer.
  </Description>
  <Rules>
    <RuleGroup Name="Custom Rules Group">
      <Rule Name="MyCustomRule" CheckId="CR0001">
        <Context>This is a custom rule.</Context>
        <Description>This is a custom rule description.</Description>
      </Rule>
    </RuleGroup>
  </Rules>
</SourceAnalyzer>

The target-Framework is 3.5 and the xml file is marked as "Embedded Resource". I copy the .dll in the install folder of StyleCop.
Thanks for help!

Developer
Nov 30, 2011 at 3:10 PM

Hi,

I could help you if you just shared (via email, dropbox, or in any other way) your entire project (or solution).

Best regards,
Oleg Shuruev

Nov 30, 2011 at 4:52 PM

Hi, 

can you give me an mail address, so I can share my Dropbox folder?

Bye

Dec 4, 2011 at 9:08 AM
Edited Dec 4, 2011 at 9:09 AM

Thanks for the help. I will implement the recommendations and hope that everything works.