"ERROR: File xxx can't be indexed twice." when analyzing a solution with a mix of C# and C++

Below is my azure pipeline to analyze a solution with a mix of C# and C++.

This is the error execute the project build command:

ERROR: Error during SonarScanner execution

ERROR: File HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

How to resolve this error? Thanks.

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/4.10.0.19059/sonar-scanner-msbuild-4.10.0.19059-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'

Log:

log.txt (54.5 KB)

Hey there.

To start, you’re using a very old version of the Scanner for MSBuild (now named the Scanner for .NET). v4.10 was released 3 years ago :dizzy_face:

Please start by upgrading to the latest version of the Scanner for .NET, v5.13, and see if the issue persists.

1 Like

Thanks, Colin @Colin
I tried 5.13, the issue persists.

Here is the latest pipeline yaml:

resources:
repositories:

trigger: none

pool: ‘Windows2022-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: ‘xxxxxx_HPCEMConnectionWizardWin’
    cliSources: ‘.’
    extraProperties: |
    sonar.cfamily.build-wrapper-output=bw-output

  • 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 /nodeReuse:False
    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

log:
log.txt (56.4 KB)


C++ code are under SRC folder:
C# code are under HPCEMConnectionWizardWin

I did not set anything in project settings:

update 2023.5.27 @Colin

I updated the following pipeline task:

- 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/

new error:

ERROR: Error during SonarScanner execution 2023-05-27T12:25:22.4759667Z File HPCEMConnectionWizardWin/src/HPCEMConnectionWizardLauncher/framework.h can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

Here is the code I like to analyze:

The C# code(*.CS) dir lists:

HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/Model/ HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/View/ HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/ViewModel/

The C++ code(.CPP,.h) dir lists:

HPCEMConnectionWizardWin/src/

verbose log:
log (4).txt (123.6 KB)

server version:
image

SonarQube extension for Azure DevOps:
version : 5.13.0

I updated following task and there is still a error:

  • task: SonarQubePrepare@5
    inputs:
    SonarQube: ‘https://sq.corp.xxxcloud.net
    scannerMode: ‘CLI’
    configMode: ‘manual’
    cliProjectKey: ‘xxx_HPCEMConnectionWizardWin’
    cliSources: ‘.\HPCEMConnectionWizardWin’
    extraProperties: |
    sonar.cfamily.build-wrapper-output=bw-output
    sonar.verbose=true

00:55:37.492 ERROR: Error during SonarScanner execution
File HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

I did not set anything in “General Settings-> analysis scope”.
I did not set sonar.sources, sonar.tests, inclusion/exclusion patterns.

And the log does not have duplicate indexed record of that file.

log:
log20230530.txt (110.7 KB)

Hey there.

If you have a Data Center Edition of SonarQube, you certainly have access to our great commercial support engineers. I suggest asking your administrators how to reach out to them, as it appears you have a fairly complex setup and could use some more help than this community forum can provide.