-1

I have a project consists of 3 C++ sub projects and a C# main project, Below is my Yaml file to analyze it in azure pipeline using SonarQube. As you can see in the YAML file, I analyze all of 4 projects using configuration for c++, so how can I analyze first 3 project using configuration for c++ and analyze the last one using configuration for .NET(C#)? Thanks.

Here is a warning from analyzing log:

WARN: Your project contains C# files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the SonarScanner for .NET 5.x or higher, see SonarScanner for .NET

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

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

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

- task: CmdLine@2  # C++ sub project
  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" KHPLib\src\KHPLib\KHPLib.vcxproj -t:Rebuild /p:configuration=release /p:platform=x64'

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

- task: CmdLine@2  # C++ sub project
  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" KConnectionWizardWin\src\KConnectionWizardSvc\KConnectionWizardSvc.vcxproj -t:Rebuild /p:configuration=release /p:platform=x64'

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

- task: CmdLine@2 # C++ sub project
  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" KConnectionWizardWin\src\KConnectionWizardLauncher\KConnectionWizardLauncher.vcxproj -t:Rebuild /p:configuration=release /p:platform=x64'

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

- task: CmdLine@2 # C# main project
  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" KConnectionWizardWin\KConnectionWizardWin.sln -t:Rebuild /p:configuration=release /p:platform=x64'

# - task: VSBuild@1 
#   inputs:
#     solution: 'KConnectionWizardWin\KConnectionWizardWin.sln'
#     platform: '$(buildPlatform)'
#     configuration: '$(buildConfiguration)'

- task: SonarQubeAnalyze@5

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

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

And this is how I analyze .net(C#) project: enter image description here

And this is how I analyze C++ project: enter image description here

Ming
  • 379
  • 1
  • 6
  • 20

2 Answers2

0

It looks like you figured it out based on your other question here: "ERROR: File xxx can't be indexed twice." when analyzing a solution with a mix of C# and C++. You need to run the BEGIN command, wrap your build command with build-wrapper, then run END command as you did in your other StackOverflow question:

      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

In any case, for future readers, you should refer to this section of the SonarQube documentation: https://docs.sonarqube.org/latest/analyzing-source-code/languages/c-family/#solution-with-mix.

For SonarCloud documentation: https://docs.sonarcloud.io/advanced-setup/languages/c-c-objective-c/#solution-with-a-mix-of-c-and-c

In the future, go to Sonar Community for future assistance. Sonar uses their own community, not StackOverflow, to help users.

  • I went to Sonar Community first and I didn't get much help there , so I post the question here. https://community.sonarsource.com/t/error-file-xxx-cant-be-indexed-twice-when-analyzing-a-solution-with-a-mix-of-c-and-c/91219/3 – Ming May 29 '23 at 06:04
0

For anyone interested

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

It would be nice if this analysis setup is added to the following documentation under .NET section: https://docs.sonarqube.org/9.9/devops-platform-integration/azure-devops-integration/

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: 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" CEMConnectionWizardWin\CEMConnectionWizardWin.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'
Ming
  • 379
  • 1
  • 6
  • 20