【问题标题】:Trying to Use MSBuild SonarQube and unable to make it work尝试使用 MSBuild SonarQube 并且无法使其工作
【发布时间】:2016-02-23 10:14:55
【问题描述】:

我一直在使用 SonarQube 进行基本级别的代码分析,但是现在我想根据 FX-COP 规则来衡量代码。因此,我尝试使用 MSBuild SonarQube 扫描仪。我彻底阅读了文档并同样设置了我的项目,但是当我执行它时出现错误。

以下是日志的摘录:

MSBuild SonarQube Runner Bootstrapper 1.0.2.0
Default properties file was found at C:\....\1c36691bf5270463\SonarQube.Analysis.xml
Loading analysis properties from C:\....\1c36691bf5270463\SonarQube.Analysis.xml
Pre-processing started.
Preparing working directories...
Checking for updates...
MSBuild SonarQube Runner Pre-processor 1.0.2.0
Loading analysis properties from C:\...\1c36691bf5270463\SonarQube.Analysis.xml
Updating build integration targets...
Fetching analysis configuration settings...
Generating rulesets...
Pre-processing succeeded.

Microsoft (R) Build Engine version 12.0.21005.1
[Microsoft .NET Framework, version 4.0.30319.34209]
Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build,
 please add the "/m" switch.
Build started 11/20/2015 1:46:41 PM.
Project "C:\Project1.sln" on node 1 (rebuild target(s)).
ValidateSolutionConfiguration:
 Building solution configuration "Debug|Any CPU".
 Build succeeded.
    9 Warning(s)
    0 Error(s)

Time Elapsed 00:01:07.86
MSBuild SonarQube Runner Bootstrapper 1.0.2.0
Default properties file was found at C:\...\1c36691bf5270463\SonarQube.Analysis.xml
Loading analysis properties from C:\...\1c36691bf5270463\SonarQube.Analysis.xml
Post-processing started.

MSBuild SonarQube Runner Post-processor 1.0.2.0 给出了几个类似于以下警告的警告:

WARNING: File is not under the project directory and cannot currently be analysed
by SonarQube.
 File: C:\Users\...\AppData\Local\Temp\2\.NETFramework,Version=v4.0.AssemblyAttributes.cs,
 project: C:\...\1c36691bf5270463\SOURCE\x\y.csproj**

呼叫声纳:

SONAR_RUNNER_OPTS is not configured. Setting it to the default value of -Xmx1024m
C:\...\1c36691bf5270463\.sonarqube\bin\sonar-runner\bin\..
SonarQube Runner 2.4
Java 1.8.0_51 Oracle Corporation (64-bit)
Windows Server 2008 R2 6.1 amd64
SONAR_RUNNER_OPTS=-Xmx1024m
INFO: Error stacktraces are turned on.
INFO: Runner configuration file: C:\...\1c36691bf5270463\.sonarqube\bin\sonar-runner\bin\..\conf\sonar-runner.properties
INFO: Project configuration file: C:\TeamCity\buildAgent\work\1c36691bf5270463\.sonarqube\out\sonar-project.properties
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: C:\...\1c36691bf5270463\.sonarqube\out\.sonar
INFO: SonarQube Server 5.1.1
13:47:51.150 INFO  - Load global repositories
13:47:51.743 INFO  - Load global repositories (done) | time=593ms
13:47:51.758 INFO  - Server id: 20151120125423
13:47:51.758 INFO  - User cache: C:\...\cache
13:47:51.758 INFO  - Install plugins
13:47:51.836 INFO  - Install JDBC driver
.
.
.
13:47:55.518 INFO  - -------------  Scan file1
13:47:55.534 INFO  - Load module settings
13:47:55.658 INFO  - Load rules
13:47:56.017 INFO  - Base dir: C:\...\1c36691bf5270463\SOURCE\xxx
13:47:56.017 INFO  - Working dir: C:\...\1c36691bf5270463\.sonarqube\out\.sonar\AC1_AC1_497EBFF2-C710-4843-8263-F534AF803D3E
13:47:56.017 INFO  - Source encoding: UTF-8, default locale: en_US
13:47:56.532 INFO  - Quality profile for cs: Sonar way
13:48:00.635 INFO  - Sensor org.sonar.plugins.csharp.CSharpFxCopProvider$CSharpFxCopSensor@73c82ec1
INFO: -----------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: -----------------------------------------------------------------
Total time: 10.156s
Final Memory: 16M/306M
INFO: -----------------------------------------------------------------
13:48:00.791  Creating a summary markdown file...
Press any key to continue . . . 

【问题讨论】:

  • 您需要通过在 SQ Scanner for MSBuild 的 conf 目录中的 SonarQube.Analysis.xml 中将 sonar.verbose 属性添加为 true 来运行“开始”阶段,或者直接在命令行中设置它使用 /d(参见docs.sonarqube.org/display/SONAR/…)。这将允许您在“结束”阶段查看有关 CSharpFxCopSensor 中的错误的更多详细信息。
  • 谢谢。 cmd窗口上的错误“必须设置属性sonar.cs.fxcop.assembly并且必须已经构建项目......”我已经阅读了很多关于这个错误的帖子并且主要做了所有的事情来解决它但是它仍然存在。我正在使用带有这些命令的批处理文件的普通命令窗口

    MSBuild.SonarQube.Runner.exe
    begin /k:"AC1" /n:"Project1" /v:"1.0" /d:sonar .host.url=localhost:9000 >>log.txt
    MSBUILD.exe Project1.sln /t:rebuild >>log.txt
    MSBuild.SonarQube.Runner.exe end >>log.txt
    msbuild-12 的版本。路径设置得当。谢谢

标签: msbuild sonarqube sonar-runner sonarqube5.1 sonarqube-msbuild-runner


【解决方案1】:

您需要在 Visual Studio 2013 或更高版本的开发人员命令提示符中运行所有命令,并且:

  • 至少使用 MSBuild 12.0
  • 已安装 .NET 4.5.2+

您遇到此错误是因为未生成 FxCop 结果。 您是否在 MSBuild 的日志中看到了 FxCop 的执行?这在 MSBuild 日志的 RunCodeAnalysis 部分中可见。

【讨论】:

  • 我已验证 msbuild 和 dot net 版本为 12 和 4.5.2 我正在我的 CI 机器上运行分析(使用 Teacmcity)。我是否需要在构建机器上安装 VS2013 才能获得 VS2013 命令提示符?
  • 由于许可问题,我无法在此特定服务器上安装 Visual Studio 2013。有没有其他的出路?这和使用 Windows SDK 7.1 命令提示符一样吗?
  • FxCop 自版本 10 起停止作为独立下载提供。它现在作为 Visual Studio 的一部分提供。因此,如果您想执行 FxCop 规则,则必须在构建代理上安装 Visual Studio。
【解决方案2】:

您可以免费获得 Visual Studio Express 2013(或 15),它们都带有各自的开发人员命令提示符。

【讨论】:

    【解决方案3】:

    您需要从命令行运行它并在命令中使用“-X”标志,这将为您提供详细的调试,我强烈建议您执行以下操作以进行故障排除。

    sonar-runner.exe <arg> <arg> -X > sonar-runnerLog.txt
    

    然后在此处读取或转储该日志。无论哪种方式,您都会对实际问题有更多了解。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-27
      • 2015-11-12
      • 2019-09-24
      • 2018-11-03
      • 1970-01-01
      • 2013-01-23
      • 1970-01-01
      相关资源
      最近更新 更多