FXCop Custom Rule does not show up in RuleSet

别来无恙 提交于 2019-12-05 19:03:10

Looks like your path is kind of shaky, remove some spacing and unwanted characters:

<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="New Rule Set" Description=" " ToolsVersion="10.0">
     <RuleHintPaths>       
         <Path>C:\App\PSI\Development\Source\JHA.ProfitStars.PSI\JHA.ProfitStars.PSI.FxCop\bin\Debug</Path>
     </RuleHintPaths>
</RuleSet>

Also adding the rulesdll to Microsoft Visual Studio [Version]\Team Tools\Static Analysis Tools\FxCop\Ruleslocation would solve the issue of having to use Rulehintpaths.

As I can't detect anything wrong with your custom rules, see if you have selected the option to show all rules:

Also, using the following BaseRule might help:

protected BaseRule(string name)
        : base(

            // The name of the rule (must match exactly to an entry
            // in the manifest XML)
            name,

            // The name of the manifest XML file, qualified with the
            // namespace and missing the extension
            typeof(BaseRule).Assembly.GetName().Name + ".Rules",

            // The assembly to find the manifest XML in
            typeof(BaseRule).Assembly)
    {
    }

Close your solution. Use the Source Control Explorer to locate your Rule Set File. Doubleclick onto your ruleset. The Rule Set Editor now should show all your custom rules. If this still doesn't work, try to use a relative path in the Path tag of the RuleHintPaths section.

Have a look at the LoadFromFile() method of the Microsoft.VisualStudio.CodeAnalysis.dll:

public static RuleSet LoadFromFile(string filePath, IEnumerable<RuleInfoProvider> ruleProviders)
    {
      RuleSet ruleSet = RuleSetXmlProcessor.ReadFromFile(filePath);
      if (ruleProviders != null)
      {
        string relativePathBase = string.IsNullOrEmpty(filePath) ? (string) null : Path.GetDirectoryName(ruleSet.FilePath);
        Dictionary<RuleInfoProvider, RuleInfoCollection> allRulesByProvider;
        Dictionary<string, IRuleInfo> rules = RuleSet.GetRules((IEnumerable<string>) ruleSet.RuleHintPaths, ruleProviders, relativePathBase, out allRulesByProvider);
        foreach (RuleReference ruleReference in (Collection<RuleReference>) ruleSet.Rules)
        {
          IRuleInfo ruleInfo;
          if (rules.TryGetValue(ruleReference.FullId, out ruleInfo))
          {
            if (ruleInfo.AnalyzerId == ruleReference.AnalyzerId)
              ruleReference.RuleInfo = ruleInfo;
            else
              CATrace.Info("RuleSet.LoadFromFile: Rule {0} was listed under analyzer id {1} in the rule set, but the corresponding IRuleInfo returned analyzer id {2}", (object) ruleReference.FullId, (object) ruleReference.AnalyzerId, (object) ruleInfo.AnalyzerId);
          }
        }
      }
      return ruleSet;
    }

If the relativePathBase is calculated wrong, the rule DLLs will not be found.

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