从命令行构建时,MSBuild警告MSB3884

时间:2015-11-19 13:08:52

标签: jenkins msbuild visual-studio-2015 msbuild-14.0

在构建服务器上构建我们的解决方案(使用Jenkins)并在MSBuild时出现以下警告:

  

C:\ Program Files   (86)\的MSBuild \ 14.0 \ BIN \ Microsoft.VisualBasic.CurrentVersion.targets(133,9):   警告MSB3884:规则集文件" ManagedMinimumRules.ruleset"不能   被发现。

在我的开发机器上执行相同的命令行调用,此警告不会出现。

有关此警告出现在构建服务器上的任何想法吗?

我已经为MSBuild打开了一个问题:https://github.com/Microsoft/msbuild/issues/361

4 个答案:

答案 0 :(得分:3)

解决方案:创建一个空的规则集文件,并将其作为命令行参数传递给MSBuild。

NoRules.ruleset文件:

<?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>     

对于Jenkins构建,添加以下MSBuild开关以覆盖项目设置并使用NoRules文件:

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

您只需将NoRules文件添加到源代码管理中即可。在MSBuild步骤之前,我选择使用批处理文件在Jenkins中动态构建它:

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%

此文件还显示Jenkins ConsoleOut显示中的注释。这应该可以帮助您了解之后为什么会这样做。

答案 1 :(得分:1)

在构建服务器上创建以下文件夹:

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

将所有规则集文件从开发计算机复制到构建服务器上。

然后通过创建包含以下内容的“addkey.reg”文件来添加以下注册表项:

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\\"

在构建服务器上运行它,重新启动,完成,警告消失。

答案 2 :(得分:0)

相关:VS2015: warning MSB3884: Could not find rule set file

检查你的csproj有一个DevEnvDir而不是VS的路径(esp vs2010)。我估计你的笔记本电脑安装了相应的VS,你的构建服务器没有。

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

答案 3 :(得分:0)

将此属性添加到msbuild命令:

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

例如,我使用了此命令

>"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"