AzureDevops- .Net 项目分析与 sonarQube 错误

AzureDevops- .Net project analysis with sonarQube error

我已经在我的 AKS(Azure Kubernetes 集群)上设置了我的 Sonar 服务器并使用了 Sonar docker 图像版本(图像:sonarqube:7.1)。

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

当我 运行 我的管道时,我收到此错误:

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 需要 v14.0.25420.1 或更高版本的 MSBuild。

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

之所以建议使用Visual Studio 2019,是因为微软可能很快就会在Azure DevOps中结束对Visual Studio 2015的支持,目前不再支持Visual Studio 2015。 Visual Studio 2017 年仍然支持,但支持将于明年结束。

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

我在这两者之间尝试了很多东西,当我使用 MSBuild 步骤的 .NetCLIBuild 时,我的声纳分析开始工作。

现在我的管道是这样的。

- 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 构建,我的管道按预期工作。