3

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

C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.VisualBasic.CurrentVersion.targets(133,9):警告 MSB3884:找不到规则集文件“ManagedMinimumRules.ruleset”。

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

任何想法为什么此警告出现在构建服务器上?

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

4

4 回答 4

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 显示中的注释。这应该可以帮助您了解您后来这样做的原因。

于 2017-01-27T13:13:54.270 回答
1

将此属性添加到 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"
于 2019-02-14T23:31:38.973 回答
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\\"

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

于 2017-05-09T02:23:59.937 回答
1

相关:VS2015:警告 MSB3884:找不到规则集文件

检查您的 csproj 是否有 DevEnvDir 而不是 VS 的路径(尤其是 vs2010)。我认为您的笔记本电脑安装了适当的 VS,而您的构建服务器没有。

<CodeAnalysisRuleSet>ManagedMinimumRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;$(DevEnvDir)\..\..\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
于 2015-12-18T15:01:14.363 回答