使用 SonarQube、MSBuild14 和 FxCop10 分析 C# VS 解决方案

Analyzing C# VS Solution using SonarQube, MSBuild14 and FxCop10

我所在的团队目前使用 VS2013,所以我安装的是 MSBuild12。 我安装了 FXCop10。 我安装了 MSBuild14。 我安装了 SonarQube Scanner for MSBuild 2.1.

I 运行 SonarQube 版本 5.6 处于演示模式。 我启用了所有规则并可以使用以下批处理脚本进行分析:

<!-- language: lang-sh-->
@echo off
REM Set FxCop10Directory="C:\Program Files (x86)\Microsoft Fxcop 10.0\"
REM Set FxCop10="C:\Program Files (x86)\Microsoft Fxcop 10.0\FxCopCmd.exe"

Set ScannerDirectory="D:\Programs\sonar-scanner-2.6.1\bin\"
Set MSBuild12="C:\Program Files (x86)\MSBuild.0\Bin\MSBuild.exe"
Set MSBuild14="C:\Program Files (x86)\MSBuild.0\Bin\MSBuild.exe"
Set Runner="MSBuild.SonarQube.Runner.exe"
Set Key="DEMO2016"
Set Name="SonarQube Internal Demo"
Set Version="0.0.0.0"

PATH=%PATH%;%ScannerDirectory%

call %Runner% begin /k:%Key% /n:%Name% /v:%Version%
call %MSBuild14% /t:Rebuild
call %Runner% end
pause

当我尝试通过将调用更改为调用 %MSBuild14% /t:Rebuild 来升级到 MSBuild14 时,出现错误。

error : FxCop must be installed when some of its rules are enabled in the SonarQube quality profile. FxCop is included as part of Visual Studio.

VS2013 附带了另一个版本的 FXCop。

如何控制 MSBuild.SonarQube.Runner 使用的版本? 如何为 MSBuild.SonarQube.Runner 设置 FxCop10?

我不知道为什么 MSBuild12 最初对我有用。 我必须导入开发环境才能在我的系统上运行。

<!-- language: none-->

@echo off
echo.
echo Setup References
Set ScannerDirectory="D:\Programs\sonar-scanner-2.6.1\bin\"
Set MSBuild14="C:\Program Files (x86)\MSBuild.0\Bin\MSBuild.exe"
Set Runner="MSBuild.SonarQube.Runner.exe"
Set vcvars="C:\LegacyApp\VisualStudio2013\VC\vcvarsall.bat"
echo.
echo Setup Runner Parameters
Set Key="DEMO2016"
Set Name="SonarQube Internal Demo"
Set Version="0.0.0.0"
echo.
echo Create Environment
PATH=%PATH%;%ScannerDirectory%
call %vcvars%
echo.
echo Runner Begin
call %Runner% begin /k:%Key% /n:%Name% /v:%Version%
echo.
echo MSBuild Rebuild
call %MSBuild14% /t:Rebuild
echo.
echo Runner End
call %Runner% end
pause

输出显示当前使用的 FxCop 版本在哪里:

<!-- language: none-->

Running Code Analysis...
C:\LegacyApp\VisualStudio2013\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe 

在命令提示符下执行该文件returns它的版本。