4

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

Anni S
  • 1,996
  • 19
  • 28
Toni Wenzel
  • 2,081
  • 2
  • 24
  • 39
  • See also this answer: https://stackoverflow.com/a/46309078/249948 By correctly installing VS2017 Build Tools, this error should not occur. – Herman Cordes Nov 21 '17 at 12:52

4 Answers4

4

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.

Wayne Mack
  • 51
  • 2
2

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>
Community
  • 1
  • 1
timB33
  • 1,977
  • 16
  • 33
  • 1
    Can you elaborate? My .csproj file does not have these tags at all. Do I need to add them somewhere? – Jan Hettich Feb 10 '16 at 18:10
  • The ManagedMinimumRules is a code analysis ruleset that comes with visual studio, I reckon that at some point you've either installed VS or one of its SDKs on your Dev machine. This when you execute locally your dev machine is happy. It's possible that your build host hasn't had either of these added and when msbuild looks for this folder it can't be found. The comment I made about vs2010 probably doesn't apply but there's a similar bug where VS2010 used to hardcode a 2010 path to this ruleset in your csproj, and then when a colleague used your solution with e.g. VS2012 the build would moan. – timB33 Feb 11 '16 at 12:56
2

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.

Rocklan
  • 7,888
  • 3
  • 34
  • 49
1

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"
markf78
  • 597
  • 2
  • 7
  • 25