英文:
"ERROR: File xxx can't be indexed twice." when analyzing a solution with a mix of C# and C++
问题
以下是我的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 Studio22\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'
<hr/>
更新 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/Model/
- HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/View/
- HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/ViewModel/
C++代码(.cpp,.h)目录列表:
- HPCEMConnectionWizardWin/src/
详细日志:https://community.sonarsource.com/uploads/short-url/pANjC2FqXe3iqumr095tLL1TmLx.txt
英文:
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 Studio22\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'
<hr/>
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
答案1
得分: 1
你需要检查是否在某种方式下两次包括了 HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config
。你应该在 SonarQubePrepare
步骤中添加 sonar.verbose=true
,并检查Sonar索引了哪些文件。然后,你可以看到重复的位置在哪里。接下来,按照 缩小焦点 的步骤,确保某些文件没有被重复索引。
为了快速解决问题,只需使用以下方法排除 HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config
文件:
sonar.exclusions= HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config
英文:
You need to check if HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config
is included twice somehow. You should add sonar.verbose=true
in the SonarQubePrepare
step 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.config
file with:
sonar.exclusions= HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论