【问题标题】:SonarQube Scanner throwing errorSonarQube 扫描仪抛出错误
【发布时间】:2018-03-18 10:41:51
【问题描述】:

我要求使用 SonarQube 来分析 .NET 项目。我安装了 sonarqube-5.6.7 并且一切正常,但是当我使用 MSBuild.SonarQube.Runner.exe 构建 .net 解决方案时出现了问题。解决方案正在成功构建,但在向 Sonar 服务器发送报告时出错。

请注意,我正在使用带有 4.5.2 框架的 Visual Studio 2012 项目,我不使用 TFS 甚至 Jenkins。

  • SonarQube.Scanner.MSBuild.exe begin /k:"key" /n:"Project name" /v:"1.0" - 这一步似乎工作正常。

  • MSBuild.exe /t:Rebuild - 这一步似乎工作正常。

  • SonarQube.Scanner.MSBuild.exe end - 此步骤失败。

失败步骤的输出:

D:\...>SonarQube.Scanner.MSBuild.exe end
SonarQube Scanner for MSBuild 3.1
Default properties file was found at C:\Users\xxxx\Downloads\sonarqube-5.6.7
\bin\SonarQube.Analysis.xml

Loading analysis properties from C:\Users\xxx\Downloads\sonarqube-5.6.7\bin
\SonarQube.Analysis.xml

Post-processing started.

The SonarQube MSBuild integration failed: SonarQube was unable to collect the re
quired information about your projects.

Possible causes:

  1. The project has not been built - the project must be built in between the b
egin and end steps

  2. An unsupported version of MSBuild has been used to build the project. Curre
ntly MSBuild 14.0 upwards are supported

  3. The begin, build or end steps have not all been launched from the same fold
er

Generation of the sonar-properties file failed.     
Unable to complete SonarQube analysis.    
15:29:11.087  Creating a summary markdown file...    
15:29:11.1  Post-processing failed. Exit code: 1

谁能告诉我我错过了什么?

如下所示,我下载了“sonar-scanner-msbuild-2.3.2.573.zip”并尝试重建目标框架版本为 4.5.2 的 Visual Studio 2012 项目并出现以下错误。我尝试使用 MSBuild 12 的直接路径进行构建,也没有提供 MSBuild 完整路径,但仍然出现错误。

D:\test\test>C:\Users\xxxx\Downloads\sonarqube-5.6.7\bin\SonarQube.Scanner.M
SBuild.exe begin /k:"org.sonarqube:sonarqube-scanner-msbuild" /n:"Test Project"
/v:"1.0"

SonarQube Scanner for MSBuild 2.3.2
Default properties file was found at C:\Users\xxxx\Downloads\sonarqube-5.6.7
\bin\SonarQube.Analysis.xml

Loading analysis properties from C:\Users\xxxx\Downloads\sonarqube-5.6.7\bin
\SonarQube.Analysis.xml

Pre-processing started.

Preparing working directories...

11:23:11.818  Updating build integration targets...

11:23:11.863  Fetching analysis configuration settings...

11:23:13.712  Generating rulesets...

11:23:13.776  Provisioning analyzer assemblies for cs...

11:23:13.778  Installing required Roslyn analyzers...

11:23:13.992  Pre-processing succeeded.

D:\test\test>MSBuild.exe /t:Rebuild

Microsoft (R) Build Engine version 4.0.30319.34209
[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 09/10/2017 11:23:29.
Project "D:\test\test\test.sln" on node 1 (Rebuild target(s)).

ValidateSolutionConfiguration:
  Building solution configuration "Debug|Any CPU".

Project "D:\test\test\test.sln" (1) is building "D:\test\test\test\test.csproj"
 (2) on node 1 (Rebuild target(s)).

CoreClean:
  Deleting file "D:\test\test\test\bin\test.dll".
  Deleting file "D:\test\test\test\bin\test.pdb".
  Deleting file "D:\test\test\test\obj\Debug\test.csprojResolveAssemblyReferenc
  e.cache".
  Deleting file "D:\test\test\test\obj\Debug\test.dll".
  Deleting file "D:\test\test\test\obj\Debug\test.pdb".
GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output fi
les are up-to-date with respect to the input files.
CoreCompile:
  C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,
  1702 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /highentropyv
  a+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framewor
  k\.NETFramework\v4.5.2\Microsoft.CSharp.dll" /reference:"C:\Program Files (x8
  6)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\mscorlib.dll
  " /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework
  \.NETFramework\v4.5.2\System.ComponentModel.DataAnnotations.dll" /reference:"
  C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework
  \v4.5.2\System.Configuration.dll" /reference:"C:\Program Files (x86)\Referenc
  e Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Core.dll" /refer
  ence:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFra
  mework\v4.5.2\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files
   (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.D
  ata.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Fr
  amework\.NETFramework\v4.5.2\System.dll" /reference:"C:\Program Files (x86)\R
  eference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Drawing.d
  ll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framewo
  rk\.NETFramework\v4.5.2\System.EnterpriseServices.dll" /reference:"C:\Program
   Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\Sy
  stem.Web.ApplicationServices.dll" /reference:"C:\Program Files (x86)\Referenc
  e Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Web.dll" /refere
  nce:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFram
  ework\v4.5.2\System.Web.DynamicData.dll" /reference:"C:\Program Files (x86)\R
  eference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Web.Entit
  y.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Fram
  ework\.NETFramework\v4.5.2\System.Web.Extensions.dll" /reference:"C:\Program
  Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\Sys
  tem.Web.Services.dll" /reference:"C:\Program Files (x86)\Reference Assemblies
  \Microsoft\Framework\.NETFramework\v4.5.2\System.Xml.dll" /reference:"C:\Prog
  ram Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2
  \System.Xml.Linq.dll" /debug+ /debug:full /optimize- /out:obj\Debug\test.dll
  /subsystemversion:6.00 /target:library /utf8output Properties\AssemblyInfo.cs
   "C:\Users\xxxx\AppData\Local\Temp\.NETFramework,Version=v4.5.2.AssemblyA
  ttributes.cs"
CopyFilesToOutputDirectory:
  Copying file from "obj\Debug\test.dll" to "bin\test.dll".
  test -> D:\test\test\test\bin\test.dll
  Copying file from "obj\Debug\test.pdb" to "bin\test.pdb".
Done Building Project "D:\test\test\test\test.csproj" (Rebuild target(s)).

Done Building Project "D:\test\test\test.sln" (Rebuild target(s)).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.71

D:\test\test>C:\Users\xxxx\Downloads\sonarqube-5.6.7\bin\SonarQube.Scanner.M
SBuild.exe end

SonarQube Scanner for MSBuild 2.3.2

Default properties file was found at C:\Users\xxxx\Downloads\sonarqube-5.6.7
\bin\SonarQube.Analysis.xml

Loading analysis properties from C:\Users\xxxx\Downloads\sonarqube-5.6.7\bin
\SonarQube.Analysis.xml

Post-processing started.
The SonarQube MSBuild integration failed: SonarQube was unable to collect the re
quired information about your projects.

Possible causes:
  1. The project has not been built - the project must be built in between the b
egin and end steps

  2. An unsupported version of MSBuild has been used to build the project. Curre
ntly MSBuild 12.0 upwards are supported

  3. The begin, build or end steps have not all been launched from the same fold
er

Generation of the sonar-properties file failed. Unable to complete SonarQube ana
lysis.

11:23:59.124  Creating a summary markdown file...
11:23:59.14  Post-processing failed. Exit code: 1

【问题讨论】:

    标签: asp.net visual-studio-2012 sonarqube sonar-runner sonarqube-scan


    【解决方案1】:

    Starting from version 3.0, SonarQube Scanner for MSBuild requires MSBuild 14 or later to work.

    您似乎拥有适用于 MSBuild 3.1 的 SonarQube 扫描仪, 但是您的项目是使用 Visual Studio 2012 构建的, 它使用 MSBuild 12。

    您需要:


    使用旧版本 (2.3.2) 您在构建步骤时遇到问题:

    "C:\Program Files (x86)\MSBuild\12.0\Bin\"MSBuild.exe /t:Rebuild
    

    这是为了能够进行分析所必需的。 根据您的评论,问题是这样解决的:

    我已通过使用目标更新 C:\Program Files (x86)\MSBuild\12.0 文件夹来解决此问题。我将目标文件夹从 MSBuild 4.0 复制到 MSBuild 12.0,它正在工作。

    【讨论】:

    • 您好,感谢您的回复。我无法将我的项目升级到 Visual Studio 2015。请您提供“SonarQube Scanner for MSBuild(低于 3.0 版)”的链接,我找不到可用于 Visual Studio 2012 的链接。
    • @SandeepRastogi 你可以在这里找到旧版本:github.com/SonarSource/sonar-scanner-msbuild/releases
    • 嗨 Janos,我找到了 MSBuild 版本,请在下面找到并指导我解决上述问题。
      D:\test\test>MSBuild.exe /ver Microsoft (R) Build Engine 版本 4.0.30319.34209 [Microsoft .NET Framework,版本 4.0.30319.34209] 版权所有 (C) Microsoft Corporation。版权所有。 4.0.30319.34209
    • @SandeepRastogi 列表中唯一可能的原因是您的 MSBuild 版本。从您的输出中,我无法判断它是否高于 12。我正在寻找方法来为此找到确凿的证据,或者输出中未提及的其他可能原因。其实我有一个想法:你的解决方案和项目都被命名为“测试”。请重命名两者,使它们都不包含“test”一词,然后重试。
    • @SandeepRastogi 最可能的解释是您的默认 msbuild.exe 低于版本 12,因此不受支持。你需要使这个命令工作:"C:\Program Files (x86)\MSBuild\12.0\Bin\"MSBuild.exe /t:Rebuild。如果你能做到这一点,那么 SonarQube 分析应该也能工作。
    猜你喜欢
    • 2018-08-01
    • 2018-12-17
    • 2017-07-20
    • 2017-03-15
    • 2017-08-25
    • 2018-09-08
    • 2017-11-02
    • 1970-01-01
    • 2017-02-12
    相关资源
    最近更新 更多