"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.

Below is the pipeline setup from commercial support engineers.

but the pipeline fails at task: “SonarQubeAnalyze”.

Do you know how to resolve that error?

trigger: none

pool: 'Windows2022'

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

steps:
- checkout: self
- checkout: Dependency

- task: CopyFiles@2
  inputs:
    SourceFolder: 'Dependency/KHPLib'
    Contents: '**'
    TargetFolder: '$(Build.SourcesDirectory)/kHPLib'

- task: NuGetToolInstaller@1

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      Invoke-WebRequest -Uri 'https://sq.corp.cloud.net/static/cpp/build-wrapper-win-x86.zip' -OutFile 'build-wrapper.zip'
      Expand-Archive -Path 'build-wrapper.zip' -DestinationPath '.' -Force
      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' -Force

- task: SonarQubePrepare@5
  inputs:
    SonarQube: 'https://sq.corp.cloud.net'
    scannerMode: 'MSBuild'
    projectKey: 'xxxxx'
    extraProperties: |
      sonar.cfamily.build-wrapper-output=bw_output
      sonar.verbose=true

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

- task: CmdLine@2
  inputs:
    script: |
      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
      
- task: SonarQubeAnalyze@5

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

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

Error:

##[error]02:14:06.592 ERROR: Error during SonarScanner execution

02:14:06.592 ERROR: Error during SonarScanner execution

##[error]java.lang.IllegalStateException: java.nio.file.NoSuchFileException: C:\agent_work\5\bw_output\build-wrapper-dump.json

Full log:
SonarQubeAnalyze.txt (183.5 KB)

I checked the agent, the bw_output\build-wrapper-dump.json exists in the build agent.

It looks like on your agent, the file exists at * C:\agent_work\5\s\bw_output\build-wrapper-dump.json*

Thanks, Colin

I update the setup using absolute path, and the error persists.


trigger: none

pool: 'Windows2022'

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

steps:
- checkout: self
- checkout: Dependency

- task: CopyFiles@2
  inputs:
    SourceFolder: 'Dependency/KHPLib'
    Contents: '**'
    TargetFolder: '$(Build.SourcesDirectory)/kHPLib'

- task: NuGetToolInstaller@1

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      Invoke-WebRequest -Uri 'https://sq.corp.cloud.net/static/cpp/build-wrapper-win-x86.zip' -OutFile 'build-wrapper.zip'
      Expand-Archive -Path 'build-wrapper.zip' -DestinationPath '.' -Force
      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' -Force

- task: SonarQubePrepare@5
  inputs:
    SonarQube: 'https://sq.corp.cloud.net'
    scannerMode: 'MSBuild'
    projectKey: 'xxxxx'
    extraProperties: |
      sonar.cfamily.build-wrapper-output=$(Build.SourcesDirectory)\bw_output
      sonar.verbose=true

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

- task: CmdLine@2
  inputs:
    script: |
      build-wrapper-win-x86\build-wrapper-win-x86-64.exe --out-dir $(Build.SourcesDirectory)\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
      
- task: SonarQubeAnalyze@5

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

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

Before the build task:

After the build task:

Analysis error:

Full log:

dev.azure.com_hpcodeway_806ecdbd-12ca-4382-bb72-c6524f7cb1a3__apis_build_builds_3237744_logs_17.txt (138.0 KB)

Hey there.

Could it be possible that something is wiping that folder by the time it gets to the SonarQube analysis?

And, I still recommend this in order to receive the best support possible (and since this is support that you pay for):

the error java.nio.file.NoSuchFileException is caused by a typo.

Below is a correct setup for analyze projects with mix of C++ and C# in Azure pipeline.

trigger: none

pool: 'Windows2022'

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

steps:
- checkout: self

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      Invoke-WebRequest -Uri 'https://sq.corp.cloud.net/static/cpp/build-wrapper-win-x86.zip' -OutFile 'build-wrapper.zip'
.      Expand-Archive -Path 'build-wrapper.zip' -DestinationPath '.' -Force
 
- task: SonarQubePrepare@5
  inputs:
    SonarQube: 'https://sq.corp.cloud.net'
    scannerMode: 'MSBuild'
    projectKey: 'xxxxx'
    extraProperties: |
      sonar.cfamily.build-wrapper-output=$(Build.SourcesDirectory)\bw_output
      sonar.verbose=true

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

- task: CmdLine@2
  inputs:
    script: |
      build-wrapper-win-x86\build-wrapper-win-x86-64.exe --out-dir $(Build.SourcesDirectory)\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
      
- task: SonarQubeAnalyze@5

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

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