AzureDevops- .net项目分析出现sonarQube错误

问题描述

我已经在我的AKS(Azure Kubernetes集群)上安装了Sonar服务器,并使用了Sonar docker镜像版本(image:sonarqube:7.1)。

我在用于.net应用程序的Azure Devops中具有CI / CD管道,并且正在使用AzureDevops SonarScanner(声纳)。

运行管道时,出现此错误:

Description : Run scanner and upload the results to the SonarQube server.
Version : 4.11.0
Author : sonarsource
Help : Version: 4.11.0. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.
/usr/bin/dotnet /home/vsts/work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/4.11.0/dotnet-sonar-scanner-msbuild/SonarScanner.MSBuild.dll end
SonarScanner for MSBuild 4.10
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
##[error]The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
Possible causes:

The project has not been built - the project must be built in between the begin and end steps
An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.
The begin,build and end steps have not all been launched from the same folder
None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.

我的管道如下所示:

- task: SonarQubePrepare@4
  inputs:
    SonarQube: 'SonarQube-Dev'
    scannerMode: 'MSBuild'
    projectKey: 'Test'
    projectName: 'Test'
    extraProperties: |
      # Additional properties that will be passed to the scanner,# Put one key=value per line,example:
      # sonar.exclusions=**/*.bin
      sonar.projectBaseDir=/src
      sonar.sources=src  

  
- task: MSBuild@1
  inputs:
    solution: '/*.sln'
    restoreNugetPackages: true
    clean: true   
    
- task: SonarQubeAnalyze@4

解决方法

看着错误,您​​正在使用SonarQube分析旧版.NET Framework应用程序,但是您的SonarQube需要MSBuild v14.0.25420.1或更高版本。

此MSBuild版本是Visual Studio 2015更新15.6.1或更高版本附带的版本。因此,您的解决方案和应用程序必须至少使用Visual Studio Visual Studio 2015更新15.6.1,否则建议的方法是使用Visual Studio 2019更新16.7.1或更高版本。

我之所以建议使用Visual Studio 2019是因为Microsoft可能会很快终止对Azure DevOps中Visual Studio 2015的支持,并且目前不再支持Visual Studio 2015。仍支持Visual Studio 2017,但其支持将在明年结束。

因此,请升级您的应用程序以使用.NET Framework v4.7.2或更高版本的目标,并使用具有最新更新(当前为15.9.26)的Visual Studio 2017或使用Visual Studio 2019进行开发。

,

我在这之间尝试了很多事情,看起来当我使用.NetCLIBuild插入MSBuild步骤之后,声纳分析就开始起作用了。

现在我的管道看起来像这样。

- task: DotNetCoreCLI@2
      inputs:
        command: 'restore'
        projects: '**/*.csproj'
        workingDirectory: '/src'
    - task: SonarQubePrepare@4
      inputs:
        SonarQube: 'SonarQube-Dev'
        scannerMode: 'MSBuild'
        projectKey: 'Wiired.Card.PauseManagement'
        projectName: 'Wiired.Card.PauseManagement'
           
    - task: DotNetCoreCLI@2
      inputs:
        command: 'build'
        projects: '**/*.sln'    
    - task: SonarQubeAnalyze@4 

问题是创建了我的CI / CD管道以构建docker映像并部署在AKS集群上。当我添加声纳分析时,我的代码实际上没有得到构建,因为在docker构建步骤中正在发生构建部分。我尝试在SonarAnalysis步骤之前添加MSBuild,但没有成功,然后尝试使用DotNetCoreCLI @ 2构建,并且管道按预期运行。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...