用fxcop看不到我的自定义规则

时间:2009-11-16 13:26:35

标签: c# fxcop

我正在尝试为fxcop开发自定义规则。

我有这段代码:

namespace TestCustomRuleFxCop
{
    public class DoTheRightThingRule : BaseIntrospectionRule
    {
        public DoTheRightThingRule()
            : base("DoTheRightThing", "TestCustomRuleFxCop.Rules", 
                    typeof(DoTheRightThingRule).Assembly)
        {
        }

        public override ProblemCollection Check(Member member)
        {
            return null; // todo
        }
    }
}

我有这个xml(名为Rules.xml并将构建操作设置为嵌入式资源)

<?xml version="1.0" encoding="utf-8" ?>
<Rules FriendlyName="My rules">
  <Rule TypeName="DoTheRightThingRule" Category="MyCategory" CheckId="MyId">
    <Name>My rule name</Name>
    <Description>My description</Description>
    <Resolution>Add Resolution</Resolution>
    <Email></Email>
    <MessageLevel Certainty="100">Warning</MessageLevel>
    <FixCategories>Breaking</FixCategories>
  </Rule>
</Rules>

我编译,运行fxcop并使用此dll添加规则。

我可以看到“我的规则”文件夹,但在其中,没有规则...

我错过了什么?

感谢您的帮助, 最好的问候

1 个答案:

答案 0 :(得分:1)

有关导致规则缺失的一些最常见问题,请参阅http://msmvps.com/blogs/calinoiu/archive/2007/04/21/no-rules-in-your-fxcop-rule-assembly.aspx。根据您提供的详细信息,我猜测问题在于您的资源名称或(如果您已粘贴确切的代码),以及您传递给基础构造函数的规则名称与您的不匹配规则类型名称(“DoTheRightThing”与“DoTheRightThingRule”)。