0

我要求使用SonarQube來分析.NET項目。我安裝了sonarqube-5.6.7,並且一切正常,但是當我使用MSBuild.SonarQube.Runner.exe創建.net解決方案時,問題就出現了。解決方案正在成功構建,但在向Sonar服務器發送報告時出現錯誤。SonarQube掃描儀拋出錯誤

請注意,我正在使用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」並試圖重建Visual Studio 2012項目,該項目的目標框架版本是4.5.2,並且得到了錯誤。我試圖用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 

回答

0

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

看來你有SonarQube掃描儀爲的MSBuild 3.1, 但你的項目是使用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,它工作。

+0

嗨,感謝您的回覆。我無法將我的項目升級到Visual Studio 2015.您能否爲我提供「MSBuild SonarQube掃描儀(3.0版以下)」的鏈接,我找不到可以用於Visual Studio 2012的鏈接。 –

+0

@SandeepRastogi you can在這裏找到舊版本:https://github.com/SonarSource/sonar-scanner-msbuild/releases/ – janos

+0

嗨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 –