Below is my Azure pipeline to analyze a solution with a mix of C# and C++.
This is the error of executing 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 can I resolve this error?
Logs: build command execute log
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'
Update 2023-05-27
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) directory lists:
- HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/Model/
- HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/View/
- HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/ViewModel/
The C++ code (.cpp,.h) directory lists:
- HPCEMConnectionWizardWin/src/
Verbose log: https://community.sonarsource.com/uploads/short-url/pANjC2FqXe3iqumr095tLL1TmLx.txt
You need to check if
HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.configis included twice somehow. You should addsonar.verbose=truein theSonarQubePreparestep and check what files are indexed by Sonar. Then you can see where the duplication lies. Next, follow Narrowing the Focus to make sure certain files are not indexed twice.For a quick workaround, just exclude that
HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.configfile with: