Статический анализ кода не работает для пользовательского набора правил
Мы пытаемся создать собственный набор правил, который можно применять в процессе сборки.
Для этого я создал настраиваемое правило и настраиваемый набор правил, но анализ не работает, однако я протестировал правило с помощью Debug -> Start External Program, и он выдал правильный xml
Уже помещены dll правил и наборы правил в папку правил и наборов правил fxcop.
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>
CS-файл правил
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;
}
}
}
набор правил
<?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>