升级到6.2版后,无法对SonarQube运行分析

升级到6.2版后,无法对SonarQube运行分析,sonarqube,sonarqube-scan,sonarqube-msbuild-runner,Sonarqube,Sonarqube Scan,Sonarqube Msbuild Runner,我试图使用MSBuild scanner在SonarQube 6.2上运行分析,但在分析的第一个C#文件上立即收到错误。 在一个只包含两个C#文件的非常简单的测试解决方案上也会发生错误。 错误如下: SonarAnalyzer for C# version 1.20.1.1275 0/2 files analyzed, starting to analyze: C:\TF\16\35\src\Net Projects\Solutions\Test\TestSonarQube\Program.cs

我试图使用MSBuild scanner在SonarQube 6.2上运行分析,但在分析的第一个C#文件上立即收到错误。
在一个只包含两个C#文件的非常简单的测试解决方案上也会发生错误。 错误如下:

SonarAnalyzer for C# version 1.20.1.1275
0/2 files analyzed, starting to analyze: C:\TF\16\35\src\Net Projects\Solutions\Test\TestSonarQube\Program.cs
Failed to analyze the file: C:\TF\16\35\src\Net Projects\Solutions\Test\TestSonarQube\Program.cs
System.UnauthorizedAccessException: Access to the path 'C:\TF\16\35\src\Net Projects\Solutions\Test\TestSonarQube\Program.cs' is denied.
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
    at SonarAnalyzer.Runner.CompilationHelper.GetSolutionFromFiles(String filePath, Encoding encoding, AnalyzerLanguage language)
    at SonarAnalyzer.Runner.Program.RunAnalysis(ScannerAnalyzerConfiguration conf)
升级之前,分析工作正常。用于运行分析的用户对要分析的所有文件具有完全权限。分析之前,文件似乎未锁定。

我正在使用以下配置:

  • 索纳库贝v。6.2
  • C#插件v 5.5.1.522
  • 用于MsBuild v2.2.0.24的声纳扫描仪
这里是完整的扫描仪日志:

SonarQube Scanner for MSBuild 2.2
Default properties file was found at C:\SonarQube\sonar-scanner-msbuild-2.2.0.24\SonarQube.Analysis.xml
Loading analysis properties from C:\SonarQube\sonar-scanner-msbuild-2.2.0.24\SonarQube.Analysis.xml
sonar.verbose=true was specified - setting the log verbosity to 'Debug'
Pre-processing started.
Preparing working directories...
Using environment variables to determine the download directory...
Removing the existing directory: C:\**root path***\Sonar\.sonarqube
Creating directory: C:\**root path***\Sonar\.sonarqube
SonarQube server URL: http://**server***:9000
SonarQube Scanner for MSBuild 2.2
10:40:36.698  Loading analysis properties from C:\SonarQube\sonar-scanner-msbuild-2.2.0.24\SonarQube.Analysis.xml
10:40:36.713  sonar.verbose=true was specified - setting the log verbosity to 'Debug'
10:40:36.715  Updating build integration targets...
10:40:36.72  Installed SonarQube.Integration.ImportBefore.targets to C:\Users\**user***\AppData\Local\Microsoft\MSBuild\14.0\Microsoft.Common.targets\ImportBefore
10:40:36.721  Installed SonarQube.Integration.ImportBefore.targets to C:\Users\**user***\AppData\Local\Microsoft\MSBuild\12.0\Microsoft.Common.targets\ImportBefore
10:40:36.724  Installed SonarQube.Integration.targets to C:\**root path***\Sonar\.sonarqube\bin\targets
10:40:36.726  Creating config and output folders...
10:40:36.726  Creating directory: C:\**root path***\Sonar\.sonarqube\conf
10:40:36.727  Creating directory: C:\**root path***\Sonar\.sonarqube\out
10:40:36.736  Fetching analysis configuration settings...
10:40:36.745  Fetching properties for project 'TestSonarQube:MAIN' from http://**server***:9000/api/properties?resource=TestSonarQube%3AMAIN...
10:40:36.746  Downloading from http://**server***:9000/api/properties?resource=TestSonarQube%3AMAIN...
10:40:37.514  Downloading from http://**server***:9000/api/updatecenter/installed_plugins...
10:40:37.575  Fetching quality profile for project 'TestSonarQube:MAIN' from http://**server***:9000/api/qualityprofiles/search?projectKey=TestSonarQube%3AMAIN...
10:40:37.575  Downloading from http://**server***:9000/api/qualityprofiles/search?projectKey=TestSonarQube%3AMAIN...
10:40:37.755  Downloading from http://**server***:9000/api/rules/search?f=repo,name,severity,lang,internalKey,templateKey,params,actives&ps=500&activation=true&qprofile=cs-sonar-way-15151&p=1...
10:40:37.898  No active rules for cs
10:40:37.953  Pre-processing succeeded.
SonarQube Scanner for MSBuild 2.2
Default properties file was found at C:\SonarQube\sonar-scanner-msbuild-2.2.0.24\SonarQube.Analysis.xml
Loading analysis properties from C:\SonarQube\sonar-scanner-msbuild-2.2.0.24\SonarQube.Analysis.xml
Post-processing started.
SonarQube Scanner for MSBuild 2.2
10:40:39.425  Loading the SonarQube analysis config from C:\**root path***\Sonar\.sonarqube\conf\SonarQubeAnalysisConfig.xml
10:40:39.428  Not running under TeamBuild
10:40:39.428  Analysis base directory: C:\**root path***\Sonar\.sonarqube
Build directory: 
Bin directory: C:\**root path***\Sonar\.sonarqube\bin
Config directory: C:\**root path***\Sonar\.sonarqube\conf
Output directory: C:\**root path***\Sonar\.sonarqube\out
Config file: C:\**root path***\Sonar\.sonarqube\conf\SonarQubeAnalysisConfig.xml
Generating SonarQube project properties file to C:\**root path***\Sonar\.sonarqube\out\sonar-project.properties
The supplied Code Analysis ErrorLog file is a valid json file and does not need to be fixed: C:\Software Development\Net Projects\Solutions\Test\TestSonarQube\bin\Debug\SampleProjectForAnalysis.exe.RoslynCA.json
WARNING: File is not under the project directory and cannot currently be analysed by SonarQube. File: C:\Users\**user***\AppData\Local\Temp\.NETFramework,Version=v4.5.1.AssemblyAttributes.cs, project: C:\Software Development\Net Projects\Solutions\Test\TestSonarQube\SampleProjectForAnalysis.csproj
Setting analysis property: sonar.visualstudio.enable=false
Writing processing summary to C:\**root path***\Sonar\.sonarqube\out\ProjectInfo.log
SONAR_SCANNER_OPTS is already set. Value: -Xmx2048m
Calling the SonarQube Scanner...
Overwriting the value of environment variable 'SONAR_SCANNER_OPTS'. Old value: -Xmx2048m, new value: -Xmx2048m
Executing file C:\SonarQube\sonar-scanner-msbuild-2.2.0.24\sonar-scanner-2.8\bin\sonar-scanner.bat
  Args: -Dsonar.scanAllFiles=true -Dproject.settings=C:\**root path***\Sonar\.sonarqube\out\sonar-project.properties 
  Working directory: C:\**root path***\Sonar
  Timeout (ms):-1
  Process id: 17152
C:\SonarQube\sonar-scanner-msbuild-2.2.0.24\sonar-scanner-2.8\bin\..
INFO: Scanner configuration file: C:\SonarQube\sonar-scanner-msbuild-2.2.0.24\sonar-scanner-2.8\bin\..\conf\sonar-scanner.properties
INFO: Project root configuration file: C:\**root path***\Sonar\.sonarqube\out\sonar-project.properties
10:40:40.025 INFO: SonarQube Scanner 2.8
10:40:40.031 INFO: Java 1.8.0_101 Oracle Corporation (64-bit)
10:40:40.032 INFO: Windows 10 10.0 amd64
10:40:40.032 INFO: SONAR_SCANNER_OPTS=-Xmx2048m
10:40:40.345 DEBUG: keyStore is : 
10:40:40.346 DEBUG: keyStore type is : jks
10:40:40.346 DEBUG: keyStore provider is : 
10:40:40.346 DEBUG: init keystore
10:40:40.347 DEBUG: init keymanager of type SunX509
10:40:40.575 INFO: User cache: C:\Users\**user***\.sonar\cache
10:40:40.575 DEBUG: Extract sonar-scanner-api-batch in temp...
10:40:40.583 DEBUG: Get bootstrap index...
10:40:40.584 DEBUG: Download: http://**server***:9000/batch_bootstrap/index
10:40:40.701 DEBUG: Get bootstrap completed
10:40:40.702 DEBUG: Create isolated classloader...
10:40:40.715 DEBUG: Start temp cleaning...
10:40:40.753 DEBUG: Temp cleaning done
10:40:40.754 DEBUG: Execution getVersion
10:40:40.764 DEBUG: Execution start
10:40:41.295 DEBUG: Publish global mode
10:40:41.454 INFO: Load global repositories
10:40:41.635 DEBUG: GET 200 http://**server***:9000/batch/global | time=176ms
10:40:41.729 INFO: Load global repositories (done) | time=276ms
10:40:41.754 INFO: User cache: C:\Users\**user***\.sonar\cache
10:40:42.059 INFO: Load plugins index
10:40:42.071 DEBUG: GET 200 http://**server***:9000/deploy/plugins/index.txt | time=12ms
10:40:42.071 INFO: Load plugins index (done) | time=12ms
10:40:42.073 DEBUG: Load plugins
10:40:42.093 DEBUG: Load plugins (done) | time=20ms
10:40:42.110 DEBUG: API compatibility mode is enabled on plugin ***custom*** Analyzer [***custom***codeanalysiscsharp] (built with API lower than 5.2)
10:40:42.112 DEBUG: API compatibility mode is enabled on plugin TFVC [scmtfvc] (built with API lower than 5.2)
10:40:42.403 DEBUG: Plugins:
10:40:42.404 DEBUG:   * C# 5.5.1.522 (csharp)
10:40:42.404 DEBUG:   * ***custom*** Analyzer 1.0.0.4 (***custom***codeanalysiscsharp)
10:40:42.404 DEBUG:   * LDAP 2.1.0.507 (ldap)
10:40:42.404 DEBUG:   * JavaScript 2.19.0.3866 (javascript)
10:40:42.405 DEBUG:   * TFVC 2.1.2 (scmtfvc)
10:40:42.426 DEBUG: Execution getVersion
10:40:42.427 INFO: SonarQube server 6.2
10:40:42.427 INFO: Default locale: "en_US", source code encoding: "UTF-8"
10:40:42.428 DEBUG: Work directory: C:\**root path***\Sonar\.sonarqube\out\.sonar
10:40:42.429 DEBUG: Execution getVersion
10:40:42.429 DEBUG: Execution execute
10:40:43.192 INFO: Process project properties
10:40:43.206 DEBUG: Process project properties (done) | time=15ms
10:40:43.320 INFO: Load project repositories
10:40:43.791 DEBUG: GET 200 http://**server***:9000/batch/project.protobuf?key=TestSonarQube%3AMAIN | time=469ms
10:40:43.904 INFO: Load project repositories (done) | time=584ms
10:40:43.980 DEBUG: Available languages:
10:40:43.980 DEBUG:   * C# => "cs"
10:40:43.980 DEBUG:   * JavaScript => "js"
10:40:43.984 INFO: Load quality profiles
10:40:44.039 DEBUG: GET 200 http://**server***:9000/api/qualityprofiles/search.protobuf?projectKey=TestSonarQube%3AMAIN | time=54ms
10:40:44.045 INFO: Load quality profiles (done) | time=61ms
10:40:44.050 INFO: Load active rules
10:40:44.097 DEBUG: GET 200 http://**server***:9000/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives&activation=true&qprofile=cs-sonar-way-15151&p=1&ps=500 | time=46ms
10:40:44.169 DEBUG: GET 200 http://**server***:9000/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives&activation=true&qprofile=js-sonar-way-47608&p=1&ps=500 | time=49ms
10:40:44.176 INFO: Load active rules (done) | time=126ms
10:40:44.251 INFO: Publish mode
10:40:44.251 DEBUG: Start recursive analysis of project modules
10:40:44.253 INFO: -------------  Scan SampleProjectForAnalysis
10:40:44.393 INFO: Load server rules
10:40:44.610 DEBUG: GET 200 http://**server***:9000/api/rules/list.protobuf | time=217ms
10:40:44.632 INFO: Load server rules (done) | time=239ms
10:40:44.695 DEBUG: Initializers : GenericCoverageSensor
10:40:44.696 INFO: Initializer GenericCoverageSensor
10:40:44.696 INFO: Initializer GenericCoverageSensor (done) | time=0ms
10:40:44.697 INFO: Base dir: C:\Software Development\Net Projects\Solutions\Test\TestSonarQube
10:40:44.697 INFO: Working dir: C:\**root path***\Sonar\.sonarqube\out\.sonar\TestSonarQube_MAIN_TestSonarQube_MAIN_F1F49A3C-2CDE-4DC2-943C-BDE756CF7E64
10:40:44.698 INFO: Source paths: Program.cs, Properties/AssemblyInfo.cs, app.config, NuGet.config, packages.config
10:40:44.698 INFO: Source encoding: UTF-8, default locale: en_US
10:40:44.699 INFO: Index files
10:40:44.703 DEBUG: Declared extensions of language C# were converted to sonar.lang.patterns.cs : **/*.cs
10:40:44.703 DEBUG: Declared extensions of language JavaScript were converted to sonar.lang.patterns.js : **/*.js
10:40:44.710 DEBUG: Language of file 'Program.cs' is detected to be 'cs'
10:40:44.711 DEBUG: Language of file 'Properties/AssemblyInfo.cs' is detected to be 'cs'
10:40:44.728 INFO: Analyzer working directory does not exist
10:40:44.729 INFO: 2 files indexed
10:40:44.737 INFO: Quality profile for cs: Sonar way
10:40:44.741 DEBUG: Code colorizer, supported languages: 
10:40:45.768 DEBUG: 'Generic Coverage Report' skipped because one of the required properties is missing
10:40:45.768 DEBUG: 'Generic Test Executions Report' skipped because one of the required properties is missing
10:40:45.779 DEBUG: 'JavaScript Squid Sensor' skipped because there is no related file in current project
10:40:45.781 DEBUG: Sensors : Lines Sensor -> SCM Sensor -> C# -> Coverage Report Import -> Coverage Report Import -> Unit Test Results Import -> Zero Coverage Sensor -> Code Colorizer Sensor -> CPD Block Indexer
10:40:45.782 INFO: Sensor Lines Sensor
10:40:45.800 INFO: Sensor Lines Sensor (done) | time=18ms
10:40:45.807 INFO: Sensor SCM Sensor
10:40:45.840 INFO: Sensor SCM Sensor (done) | time=33ms
10:40:45.841 INFO: Sensor C#
10:40:45.859 INFO: SonarAnalyzer.Scanner needs to be executed: true
10:40:47.974 INFO: SonarAnalyzer for C# version 1.20.1.1275
10:40:48.355 INFO: 0/2 files analyzed, starting to analyze: C:\Software Development\Net Projects\Solutions\Test\TestSonarQube\Program.cs
10:40:49.606 ERROR: Failed to analyze the file: C:\Software Development\Net Projects\Solutions\Test\TestSonarQube\Program.cs
10:40:49.611 ERROR: System.UnauthorizedAccessException: Access to the path 'C:\Software Development\Net Projects\Solutions\Test\TestSonarQube\Program.cs' is denied.
10:40:49.611 ERROR:    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
10:40:49.611 ERROR:    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
10:40:49.611 ERROR:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
10:40:49.611 ERROR:    at SonarAnalyzer.Runner.CompilationHelper.GetSolutionFromFiles(String filePath, Encoding encoding, AnalyzerLanguage language)
10:40:49.612 ERROR:    at SonarAnalyzer.Runner.Program.RunAnalysis(ScannerAnalyzerConfiguration conf)
10:40:49.637 INFO: ------------------------------------------------------------------------
10:40:49.637 INFO: EXECUTION FAILURE
10:40:49.637 INFO: ------------------------------------------------------------------------
10:40:49.637 INFO: Total time: 9.694s
10:40:49.769 INFO: Final Memory: 47M/254M
10:40:49.769 INFO: ------------------------------------------------------------------------
10:40:49.770 ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: The .NET analyzer failed with exit code: 1 - Verify that the .NET Framework version 4.5.2 at least is installed.
    at org.sonar.plugins.csharp.CSharpSensor.analyze(CSharpSensor.java:159)
    at org.sonar.plugins.csharp.CSharpSensor.executeInternal(CSharpSensor.java:104)
    at org.sonar.plugins.csharp.CSharpSensor.execute(CSharpSensor.java:82)
    at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
    at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:57)
    at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:49)
    at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:78)
    at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:182)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
    at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:247)
    at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:242)
    at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:240)
    at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:232)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
    at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47)
    at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:86)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
    at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:115)
    at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:116)
    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
    at com.sun.proxy.$Proxy0.execute(Unknown Source)
    at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
    at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
    at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:110)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:74)
    at org.sonarsource.scanner.cli.Main.main(Main.java:61)
10:40:49.806 ERROR: 
10:40:49.806 ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
Process returned exit code 1
The SonarQube Scanner did not complete successfully
10:40:49.946  Creating a summary markdown file...
10:40:49.948  Post-processing failed. Exit code: 1

我们以前没有见过这个问题,也无法重新处理。您能否与资源监视器检查哪些进程与句柄关联
C:\TF\16\35\src\Net Projects\Solutions\Test\testsonaqube\Program.cs
?使用进程监视器,我可以看到以下进程正在访问该文件(按顺序):MSBuild.exe SonarQube.Scanner.MSBuild.exe java.exe SonarAnalyzer.Scanner.exe-->ACCESS DENIEDI我试图恢复到SonarQube版本6.1,我意识到问题与SonarQube版本无关,而与C#插件版本有关。安装C#插件v后会出现此问题。5.5.1.522,无论我使用的是SonarQube的哪个版本。使用C#插件v。5.5.0.475在SonarQube 6.2中也能正常工作。我一开始并没有意识到这一点,因为我同时升级了SonarQube和C#插件。您是使用msbuild12还是msbuild14构建解决方案?能否检查
C:\TF\16\35\src\Net Projects\Solutions\Test\testsonaqube\Program.cs
是否为只读?我正在使用msbuild14。这些文件都是只读的。我现在尝试(根据您的提示)删除只读标志,问题消失了。不幸的是,这不是解决方案,因为文件由TFS控制,并且只读标志对于TFS来说很重要,它可以在不签出的情况下跟踪已更改的内容(在Visual Studio之外)。我们以前没有看到过这个问题,也无法重新设置它。您能否与资源监视器检查哪些进程与句柄关联
C:\TF\16\35\src\Net Projects\Solutions\Test\testsonaqube\Program.cs
?使用进程监视器,我可以看到以下进程正在访问该文件(按顺序):MSBuild.exe SonarQube.Scanner.MSBuild.exe java.exe SonarAnalyzer.Scanner.exe-->ACCESS DENIEDI我试图恢复到SonarQube版本6.1,我意识到问题与SonarQube版本无关,而与C#插件版本有关。安装C#插件v后会出现此问题。5.5.1.522,无论我使用的是SonarQube的哪个版本。使用C#插件v。5.5.0.475在SonarQube 6.2中也能正常工作。我一开始并没有意识到这一点,因为我同时升级了SonarQube和C#插件。您是使用msbuild12还是msbuild14构建解决方案?能否检查
C:\TF\16\35\src\Net Projects\Solutions\Test\testsonaqube\Program.cs
是否为只读?我正在使用msbuild14。这些文件都是只读的。我现在尝试(根据您的提示)删除只读标志,问题消失了。不幸的是,这不是解决方案,因为文件是由TFS控制的,并且只读标志对于TFS很重要,它可以在不签出的情况下跟踪已更改的内容(在Visual Studio之外)。