VS2015: warning MSB3884: Could not find rule set file

C#MsbuildVisual Studio-2015Code Analysis

C# Problem Overview


After upgrading my WinForms VS2013 project to VS2015, I started seeing the MSB3884 "Could not find rule set file" warning.

A Google search turned up one MSDN article, which a Stack Overflow article points to as well as numerous other sites.

Similar Question: 33020507 MSDN: VS2015 MSB3884 Warning

I have both VS2013 and VS2015 installed.

The project files giving the warnings (and those that do not), do not have these entries.

<CodeAnalysisRuleSetDirectories>
<CodeAnalysisRuleDirectories> 

If I delete the other two entries from the project file, then the problem goes away, which is obvious, as there is no rule file set.

<CodeAnalysisIgnoreBuiltInRuleSets> 
<CodeAnalysisIgnoreBuiltInRules>

I am trying to build externally using msbuild, however VS2015 tends to show the problem too.

Interestingly enough, if I click on the open button in the project properties Code Analyzer area, I do get the file.

Specifying a different rule set makes no difference. That makes me think that possibly, there is an environment variable setting, not that any come to mind. Code Analyzers is a function of the project file. I can add a directory attribute, but the consensus is to take out paths, the <CodeAnalysisRule*Directories>.

The GUI uses defaults:

VS2015 Project Properties Code Analysis tab'

Here is a typical project file fragment.

  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\x86\Debug\</OutputPath>
    <DefineConstants>TRACE;DEBUG</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
    <CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
    <Prefer32Bit>false</Prefer32Bit>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <CodeAnalysisRuleSet>BasicCorrectnessRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\x64\Debug\</OutputPath>
    <DefineConstants>TRACE;DEBUG</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
    <CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
  </PropertyGroup>

Without getting rid of the Code Analysis lines from the project file, though saving a project file again would just add it back, how can I eliminate/fix the warning?

C# Solutions


Solution 1 - C#

I've just had the same problem after upgrading from VS2013 to VS2015.

My solution was:

  1. On the project properties go to the Code Analysis section.
  2. Select the Browse option on the list of rule sets. enter image description here
  3. Browse to the VS2015 rule sets folder. C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\Rule Sets
  4. Pick a rule set. The default used by new projects is: MinimumRecommendedRules.ruleset
  5. Rebuild. Check the warning has gone. enter image description here

Solution 2 - C#

I hit this warning after migrating from VS 2013 to VS 2015 as well. In my case the error was Could not find rule set file "AllRules.ruleset". The fix for me was to change the VisualStudioVersion setting in the .csproj file to be 14.0 so that it looks in the correct rule set folder:

VisualStudioVersion setting

After that and a rebuild, the warning was resolved. Much easier.

Solution 3 - C#

I spent some time looking at the different solutions proposed here - they each had good elements but each required some adjustments. I found a clean solution to be:

Locate an existing or create a <PropertyGroup> element in the project file that has NO conditions (e.g configuration or platform) i.e that will apply to all configurations on all platforms. To this element add a <CodeAnalysisRuleSetDirectories> element specifying the relative path to the "Rule Set" directory from the current dev env directory, e.g:

<PropertyGroup>
    <CodeAnalysisRuleSetDirectories>$(DevEnvDir)\..\..\Team Tools\Static Analysis Tools\Rule Sets</CodeAnalysisRuleSetDirectories>
</PropertyGroup>

Solution 4 - C#

I got rid of this warning by setting <CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>

Solution 5 - C#

You said your project files giving off the warnings did not contain any <CodeAnalysisRuleSetDirectories> entry.

Mine did not either, and like you I get the file if I click the Open button in the project properties Code Analysis section.

However, searching all project files in the solution turned up two projects which did have <CodeAnalysisRuleSetDirectories> tags, and those tags contained an older version of the Visual Studio reference in the path.

Fixing those paths fixed my problem, and I've just confirmed that the project which was raising the error references a project which referenced the projects which contained the bad <CodeAnalysisRuleSetDirectories> entries.

So search the whole solution and fix all <CodeAnalysisRuleSetDirectories> paths, or try removing them.

In my case

<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>

became

<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>

(Jon Shadforth's answer also worked for me, but I didn't like adding the path to more projects - as timB33 commented)

Solution 6 - C#

Had this when compiling a solution upgraded from VS2015 to VS2017 but had MSBuild 14 in the path (C:\Program Files (x86)\MSBuild\14.0\Bin). Changed to ensure 15 was in the path (C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin) and all worked.

Solution 7 - C#

I had this error on my build server which has Visual Studio Build Tools on it rather than Visual Studio.

The solution for me was to use the installer to enable Static analysis tools in the individual components list.

Solution 8 - C#

These binary analyzers are now deprecated link.

I am using VS 2019 and my solution was to edit the projects files and remove all lines related to the CodeAnalysis, in all PropertyGroups:

Before:

before edit

After:

after edit

*To edit the .vbproj or .csproj in Visual Studio you need to unload the project.

-Perform a right-click in solution and then unload the project.

-Perform a right-click again and go to edit 'fileName'

I didn't try but this solution must work in VS 2015, VS 2017 too.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSarah WeinbergerView Question on Stackoverflow
Solution 1 - C#Jon ShadforthView Answer on Stackoverflow
Solution 2 - C#RJ CuthbertsonView Answer on Stackoverflow
Solution 3 - C#RicibobView Answer on Stackoverflow
Solution 4 - C#Lu55View Answer on Stackoverflow
Solution 5 - C#TreerView Answer on Stackoverflow
Solution 6 - C#Andrew HarrisView Answer on Stackoverflow
Solution 7 - C#AdamView Answer on Stackoverflow
Solution 8 - C#fsbflavioView Answer on Stackoverflow