Static code analysis not working for custom ruleset

本小妞迷上赌 提交于 2021-01-07 06:37:44

问题


We are trying to have our own custom ruleset which we can apply during build process.

For this I've created custom rule and custom ruleset but analysis doesn't work however I've tested the rule using Debug--> Start External program and it produced correct xml

Already placed rule dll and ruleset inside fxcop rule and ruleset folder

Rule XML

 <?xml version="1.0" encoding="utf-8" ?>
    <Rules>
      <Rule TypeName="CustomRule" Category="Performance" CheckId="R001"  >
        <Name>AvoidUsingVirtualMethods</Name>
        <Description>Rule that will identify if the target assembly contains virtual methods. </Description>
        <Url></Url>
        <Resolution>Avoid using virtual methods.</Resolution>
        <Email>joydipkanjilal@yahoo.com</Email>
        <MessageLevel Certainty="100">Warning</MessageLevel>
        <Message Certainty="100">Warning</Message>
        <FixCategories>NonBreaking</FixCategories>
        <Owner />
      </Rule>
    </Rules>

Rule CS file

using System;
[assembly: CLSCompliant(true)]
namespace CustomRules
{
    using Microsoft.FxCop.Sdk;
    public class CustomRule : BaseIntrospectionRule
    {
        public CustomRule() : base("CustomRule", "CustomRules.CustomRule", typeof(CustomRule).Assembly)
        {

    }
    public override ProblemCollection Check(Member member)
    {
        Method method = member as Method;
        bool isVirtual = method.IsVirtual;

        if (isVirtual)
        {
            Resolution resolution = GetResolution(new string[] { method.ToString() });
            Problems.Add(new Problem(resolution));
        }
        return Problems;
    }
}

}

RuleSet

<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="xxxxxx" Description="This RuleSet will be used for Checking Code Quality in xxxxxx Project" ToolsVersion="16.0">
  <Localization ResourceAssembly="CustomRules.dll" ResourceBaseName="CustomRules">
    <Name Resource="xxxxxx_Custom_Rules" />
    <Description Resource="xxxxxx_Custom_Description" />
  </Localization>


  <RuleHintPaths>
    <Path>C:\Projects\CustomRules\CustomRules\bin\Debug</Path>
  </RuleHintPaths>
  <Include Path="xxxxxxcustom.ruleset" Action="Default" />
</RuleSet>

来源:https://stackoverflow.com/questions/65274613/static-code-analysis-not-working-for-custom-ruleset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!