Stylecopanalyzers: CA0064

Created on 8 Apr 2016  路  16Comments  路  Source: DotNetAnalyzers/StyleCopAnalyzers

My team and I are getting the following warning when we build a solution that is using this analyzer.

CA0064 : No analysis was performed because the specified rule set could not be loaded or did not contain any managed code analysis rules.

Reference definition from Microsoft.

MS, says we probably don't have rulesets checked, but this really does not make sense to me. I'm afraid we didn't enable/install the analyzer correctly. I have followed both Configuration.md & KnownChanges.md.

What could I have missed? Does anyone else get this warning?

Specific questions that cause me to doubt my install

  1. In VS2015 on the project property's page for "Code Analysis", do you check "Enable Code Analysis on Build"?
  2. When you open the ruleset file, is "StyleCop.Analyzers" the only item checked?
question resolved

Most helpful comment

I think I understand what the problem is.

"Code Analysis" now combines what used to be StyleCop and FxCop. Source Analysis (StyleCop) is done in CSC as part of the compile. Binary Analysis (FxCop) is a separate command run after the build. They both use the same ruleset. The "Enable Code Analysis on Build" check is applying only to binary analysis (FxCop).

FxCop uses the same .ruleset file as csc (Roslyn) but only uses the "Managed Binary Analysis" rules. If you run FxCop but don't have any of these rules checked, it will report CA0064.

To get rid of CA0064, either enable one of the "Managed Binary Analysis" rules, or uncheck "Enable Code Analysis on Build." The source analyzers will still run.

All 16 comments

What does your .ruleset look like that you have configured in the CSPROJ for the build configuration you are attempting to run?

Contents of this file:
<CodeAnalysisRuleSet>..\xyz.ruleset</CodeAnalysisRuleSet>

In the project file, I have the following line
<CodeAnalysisRuleSet>..\..\..\..\..\Wellness-Internal\TeamCode\StyleCop\WellnessInternalTeamCodingStandards.ruleset</CodeAnalysisRuleSet>

this path is full of slashes because I don't have the ruleset file included in my project. I want this one ruleset file to be used as the standard for a bunch of solutions, so i have this file outside of the solution folder for the specific project. I read other people COPY the ruleset file for each solution, while i could do that, i'm concerned about maintaining the file in different teams' solutions.

Out of curiosity, I changed the path to a something within the solution folder, AND the warning went away.

..\Build\WellnessInternalTeamCodingStandards.ruleset

Now I'm wondering how you would manage multiple teams & solutions? How can I set a standard ruleset and ensure everyone uses it? How to handle if the team decides to change a rule and needs to update all the solutions using the ruleset?

I have a ruleset outside of my solution folder as well, are you sure that path was resolving to the ruleset file on the machine that was having the issue?

I am encountering same issue. In my configuration ruleset is in same folder as solution file, and one level higher that project files. Moving it one level down didn't help. This warning is only shown, when no actual warnings are found.

I also get this and I'm not sure why. My ruleset file is stored at solution level rather than each project.

Okay, I found way to reliable reproduce and fix it. In my case it was due to code analysis properties (RunCodeAnalysis and CodeAnalysisRuleSet) were in csproj in common property group rather than in per-configuration section. Being smartass and copying them into all 30 csproj files instead of editing project properties in ui not payed out. Anyway, it's seem to be either just StyleCop Analyzers or StyleCop Analyzers + Visual Studio issue: I tried same with Microsoft rule sets, and it didn't reproduce.

I'm getting this as well - my .ruleset is in the solution folder.

Oddly the stylecop rules are being processed, so CA0064 is either incorrectly being reported or not for these.

Edit: For the record, I don't have a common property group; the code analysis settings are applied in configuration specific sections.

@professor-k , can you expand on what you mean by "in csproj in common property group rather than in per-configuration section." I don't understand what you mean. I look in my csproj and see this for the different build configurations i have

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DEV|AnyCPU'">
  <Optimize>false</Optimize>
  <DebugSymbols>true</DebugSymbols>
  <OutputPath>bin\DEV\</OutputPath>
  <DefineConstants>DEBUG;TRACE</DefineConstants>
  <DebugType>full</DebugType>
  <PlatformTarget>AnyCPU</PlatformTarget>
  <ErrorReport>prompt</ErrorReport>
  <CodeAnalysisRuleSet>..\Build\WellnessInternalTeamCodingStandards.ruleset</CodeAnalysisRuleSet>
  <DocumentationFile>bin\DEV\ASH.EmDSessions.DAL.XML</DocumentationFile>
  <RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>

@MADCookie Your rule set is only enabled when the build configuration is DEV and the build platform is AnyCPU. That's because your PropertyGroup element has a Condition attribute making that limitation (also referred above to as a per-configuration section). If you want the rule set to be applied uniformly, you need to remove the <CodeAnalysisRuleSet> from these elements, and add a new one that doesn't have the Condition limitation:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DEV|AnyCPU'">
  <Optimize>false</Optimize>
  <DebugSymbols>true</DebugSymbols>
  <OutputPath>bin\DEV\</OutputPath>
  <DefineConstants>DEBUG;TRACE</DefineConstants>
  <DebugType>full</DebugType>
  <PlatformTarget>AnyCPU</PlatformTarget>
  <ErrorReport>prompt</ErrorReport>
  <DocumentationFile>bin\DEV\ASH.EmDSessions.DAL.XML</DocumentationFile>
  <RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<!-- other conditional sections... -->
<PropertyGroup>
  <CodeAnalysisRuleSet>..\Build\WellnessInternalTeamCodingStandards.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

Doing so is exactly what was causing subj issue in my case. Now I have one copy in Debug section, and another copy in Release.

@professor-k It may have been a problem with the location of your property group relative to others in the project file. The strategy I described is the one we actually use, so we know it works at least for this project. 馃槃

May be. Instead of fourth section, I was adding lines to first one.

I'm also seeing this, with a similar amount of mystery to those above! I can confirm the following:

  • It only happens when StyleCop.Analyzers is added as an Analyzer in the .csproj file
  • It only happens when StyleCop.Analyzers overrides are present in the .ruleset file
  • It only happens when there are otherwise no StyleCop.Analyzer diagnostics (at any level)

Moving the .ruleset around and experimenting with PropertyGroup settings hasn't changed anything, I still get CA0064 on any otherwise-clean run.

I think I understand what the problem is.

"Code Analysis" now combines what used to be StyleCop and FxCop. Source Analysis (StyleCop) is done in CSC as part of the compile. Binary Analysis (FxCop) is a separate command run after the build. They both use the same ruleset. The "Enable Code Analysis on Build" check is applying only to binary analysis (FxCop).

FxCop uses the same .ruleset file as csc (Roslyn) but only uses the "Managed Binary Analysis" rules. If you run FxCop but don't have any of these rules checked, it will report CA0064.

To get rid of CA0064, either enable one of the "Managed Binary Analysis" rules, or uncheck "Enable Code Analysis on Build." The source analyzers will still run.

I confirm that the solution proposed by @frankracis-work resolved the issue for us.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iron9light picture iron9light  路  4Comments

drewnoakes picture drewnoakes  路  3Comments

mzhukovs picture mzhukovs  路  4Comments

MartyIX picture MartyIX  路  5Comments

wmjordan picture wmjordan  路  6Comments