“错误:文件 xxx 无法索引两次。”混合使用 C# 和 C++ 分析解决方案时

问题描述 投票:0回答:1

下面是我的 Azure 管道,用于分析混合使用 C# 和 C++ 的解决方案。

这是执行项目构建命令的错误:

错误:SonarScanner 执行期间出错错误:文件 HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config 不能 索引两次。请检查包含/排除模式是否产生 主文件和测试文件的不相交集

如何解决此错误?

日志:构建命令执行日志

resources:
  repositories:
  - repository: Dependency
    type: githubenterprise
    endpoint: https://github.azc.ext.xxx.com
    name: cloud-client/Dependency

trigger: none

pool: 'SWindows2022-DEV'

variables:
  buildPlatform: 'x64'
  buildConfiguration: 'Release'

steps:
- checkout: self
- checkout: Dependency

- script: |
     move Dependency/KHPLib $(Build.SourcesDirectory)

- task: NuGetToolInstaller@1


- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      Invoke-WebRequest -Uri 'https://sq.corp.xxxcloud.net/static/cpp/build-wrapper-win-x86.zip' -OutFile 'build-wrapper.zip'
      Expand-Archive -Path 'build-wrapper.zip' -DestinationPath '.'
      Invoke-WebRequest -Uri 'https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/5.13.0.66756/sonar-scanner-msbuild-5.13.0.66756-net46.zip' -OutFile 'sonar-scanner-msbuild.zip'
      Expand-Archive -Path 'sonar-scanner-msbuild.zip' -DestinationPath './SonarScanner'

- task: VSBuild@1
  inputs:
    solution: 'KHPLib\src\KHPLib\KHPLib.vcxproj'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: SonarQubePrepare@5
  inputs:
    SonarQube: 'https://sq.corp.xxxcloud.net'
    scannerMode: 'CLI'
    configMode: 'manual'
    cliProjectKey: 'xxx_HPCEMConnectionWizardWin'
    cliSources: '.'
    extraProperties: |
      sonar.cfamily.build-wrapper-output=bw-output
      sonar.java.file.suffixes=-

- task: CmdLine@2
  inputs:
    script: |
      SonarScanner\SonarScanner.MSBuild.exe begin /k:"xxx_HPCEMConnectionWizardWin" /n:"HPCEMConnectionWizardWin\HPCEMConnectionWizardWin.sln" /v:"1.0" /d:sonar.cfamily.build-wrapper-output="bw-output"
      build-wrapper-win-x86\build-wrapper-win-x86-64.exe --out-dir bw-output "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe" HPCEMConnectionWizardWin\HPCEMConnectionWizardWin.sln -t:Rebuild /p:configuration=release /p:platform=x64
      SonarScanner\SonarScanner.MSBuild.exe end

- task: SonarQubeAnalyze@5

- task: SonarQubePublish@5
  inputs:
    pollingTimeoutSec: '300'

- task: sonar-buildbreaker@8
  inputs:
    SonarQube: 'https://sq.corp.xxxcloud.net'

更新2023-05-27

我更新了以下管道任务:

- task: SonarQubePrepare@5
  inputs:
    SonarQube: 'https://sq.corp.xxxcloud.net'
    scannerMode: 'CLI'
    configMode: 'manual'
    cliProjectKey: 'xxx_HPCEMConnectionWizardWin'
    cliSources: '.'
    extraProperties: |
      sonar.cfamily.build-wrapper-output=bw-output
      sonar.java.file.suffixes=-
      sonar.verbose=true
      sonar.sources=HPCEMConnectionWizardWin/src/,HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/Model/,HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/View/,HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/ViewModel/

新错误:

错误:SonarScanner 执行期间出错 2023-05-27T12:25:22.4759667Z 文件 HPCEMConnectionWizardWin/src/HPCEMConnectionWizardLauncher/framework.h 无法索引两次。请检查包含/排除模式是否为主文件和测试文件生成不相交的集

这是我喜欢分析的代码:

C# 代码 (*.cs) 目录列表:

HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/模型/ HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/查看/ HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/ViewModel/

C++ 代码(.cpp、.h)目录列表:

HPCEMConnectionWizardWin/src/

详细日志:https://community.sonarsource.com/uploads/short-url/pANjC2FqXe3iqumr095tLL1TmLx.txt

c# c++ sonarqube sonarqube-scan sonar-runner
1个回答
1
投票

您需要检查

HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config
是否以某种方式包含两次。您应该在
sonar.verbose=true
步骤中添加
SonarQubePrepare
并检查 Sonar 索引了哪些文件。然后你就可以看到重复的地方了。接下来,按照缩小焦点确保某些文件不会被索引两次。

要快速解决此问题,只需使用以下命令排除该

HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config
文件:

sonar.exclusions= HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config
© www.soinside.com 2019 - 2024. All rights reserved.