Domanda

I try to find unused methods in my database layer, cause I just copied it from the old project and check what I still need and what not. But fxcop doesn't display the expected errors. There are several methods, that are not called, but they are not listed.

I changed all the methods from public to internal, but it still doesn't display the errors.

The class has the following structure:

namespace mynamspace {
    public partial class WebsiteModel {
        static ILog log = LogManager.GetLogger(typeof(WebsiteModel));

        manyunusedmethods
    }
}

Had anybody else this problem? The other part of WebsiteModel is of the type DbContext

EDIT I tried a few things, and it seems like it never shows the error CA1811. What am I doing wrong?

My ruleset file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Coding Lizards fxcop ruleset" Description="Dieser Regelsatz enthält alle Regeln. Das Ausführen dieses Regelsatzes führt möglicherweise zu einer hohen Anzahl gemeldeter Warnungen. Verwenden Sie diesen Regelsatz, um einen Überblick über alle Probleme in Ihrem Code zu erhalten. Dies kann Ihnen bei der Entscheidung behilflich sein, welche der spezifischeren Regelsätze für Ihre Projekte am besten geeignet sind." ToolsVersion="11.0">
  <IncludeAll Action="Warning" />
  <Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
    <Rule Id="CA1811" Action="Error" />
    <Rule Id="CA1823" Action="Error" />
    <Rule Id="CA1804" Action="Error" />
    <Rule Id="CA1801" Action="Error" />
  </Rules>
</RuleSet>
È stato utile?

Soluzione

It works for me on VS2013 with the following custom ruleset:

<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Uncalled Private Code" Description="Custom Ruleset" ToolsVersion="12.0">
  <Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
    <Rule Id="CA1811" Action="Error" />
  </Rules>
</RuleSet>

CA1811 in action

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top