MSBuild Warning MSB3884 when building from command line

4.9k views Asked by At

When building our solution on the build server (using Jenkins) with MSBuild 14 following warning occurs:

C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.VisualBasic.CurrentVersion.targets(133,9): warning MSB3884: ruleset file "ManagedMinimumRules.ruleset" could not be found.

Executing the same command line call on my dev machine, this warning won't appear.

Any ideas why this warning appears on the build server?

I've already opened an issue for MSBuild: https://github.com/Microsoft/msbuild/issues/361

4

There are 4 answers

0
Wayne Mack On

Solution: Create an empty rule set file and pass that as a command line parameter to MSBuild.

NoRules.ruleset file:

<?xml version="1.0" encoding="utf-8"?> 
<!--                                   
Problem: warning MSB3884 
  Visual Studio 2015 includes references to MinimumRecommendedRules.ruleset in .csproj files. 
  MSBuild 10 cannot find this reference and generates warning MSB3884. 

Solution: Create NoRules.ruleset [this file] and pass it to MSBuild in a command switch.  Need to pass full path name to MSBuild. 
Example: MSBuild /property:CodeAnalysisRuleSet="$Workspace\NoRules.ruleset" 

References: 
  https://msdn.microsoft.com/en-us/library/dd264949.aspx 
  https://msdn.microsoft.com/en-us/library/ms164311.aspx 
-->      
<RuleSet Name="NoRules" Description="This rule set contains no rules." ToolsVersion="14.0"> 
</RuleSet>     

For a Jenkins build, add the following MSBuild switch to override the project settings and use the NoRules file:

/property:CodeAnalysisRuleSet="$Workspace\NoRules.ruleset" 

You can just add the NoRules file to source control. I chose to build it on the fly in Jenkins with a Batch file prior to the MSBuild step:

set NoRules=NoRules.ruleset
@echo Making %NoRules%
if not exist %NoRules% (
  @echo ^<?xml version="1.0" encoding="utf-8"?^> >%NoRules%
  @echo ^<!--                                   >>%NoRules%
  call :WriteToFile %NoRules% "Problem: warning MSB3884"
  call :WriteToFile %NoRules% "  Visual Studio 2015 includes references to MinimumRecommendedRules.ruleset in .csproj files."
  call :WriteToFile %NoRules% "  MSBuild 10 cannot find this reference and generates warning MSB3884."
  @echo.          >>%NoRules%
  call :WriteToFile %NoRules% "Solution: Create NoRules.ruleset [this file] and pass it to MSBuild in a command switch."
  call :WriteToFile %NoRules% "  Need to pass full path name to MSBuild."
  @echo Example: MSBuild /property:CodeAnalysisRuleSet="$WORKSPACE\NoRules.ruleset" >>%NoRules%
  @echo.          >>%NoRules%
  call :WriteToFile %NoRules% "References:"
  call :WriteToFile %NoRules% "  https://msdn.microsoft.com/en-us/library/dd264949.aspx"
  call :WriteToFile %NoRules% "  https://msdn.microsoft.com/en-us/library/ms164311.aspx"
  @echo --^>      >>%NoRules%
  @echo ^<RuleSet Name="NoRules" Description="This rule set contains no rules." ToolsVersion="14.0"^> >>%NoRules%
  @echo ^</RuleSet^> >>%NoRules%
)
exit /b %errorlevel%

:WriteToFile
  @echo %~2 >>%1
exit /b %errorlevel%

This file also shows the comments in the Jenkins ConsoleOut display. This should help you know what why you did this later.

2
timB33 On

related: VS2015: warning MSB3884: Could not find rule set file

Check your csproj has a DevEnvDir and not a path to VS (esp vs2010). I reckon your laptop's got the appropriate VS installed and your build server doesn't.

<CodeAnalysisRuleSet>ManagedMinimumRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;$(DevEnvDir)\..\..\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
0
markf78 On

Add this property to the msbuild command:

CodeAnalysisRuleSetDirectories="C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Team Tools\Static Analysis Tools\Rule Sets".

For example, I used this command

>"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild" solutionName.sln /target:build /property:Configuration=Release;CodeAnalysisRuleSetDirectories="C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Team Tools\Static Analysis Tools\Rule Sets"
0
Rocklan On

Create the following folder on your build server:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\Rule Sets

Copy all of your ruleset files from your dev machine onto the build server.

Then add the following registry key by creating a "addkey.reg" file with the following contents:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\14.0\Setup\EDev]
"StanDir"="C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Team Tools\\Static Analysis Tools\\"

Run it on your build server, reboot, done, warning gone.