C/C++/Objective-C Error during SonarScanner execution for .net project

Must-share information (formatted with Markdown):

  • SonarQube version: Version 9.5

  • what are you trying to achieve
    Trying sonarqube analysis for .net projects

  • what have you tried so far to achieve this
    added following steps

    Prepare Analysis Configuration task for SonarQube

    • task: SonarQubePrepare@4
      inputs:
      SonarQube: ‘project-reposqserviceconnection’
      scannerMode: ‘MSBuild’
      projectKey: ‘project-key’

    • task: MSBuild@1
      displayName: ‘Build Solution’
      inputs:
      solution: ‘$(solutionName)’
      platform: ‘$(buildPlatform)’
      configuration: ‘${{ parameters.BuildConfiguration }}’
      msbuildArguments: ‘$(buildTarget) $(buildParameters)’

Run Code Analysis task for SonarQube

  • task: SonarQubeAnalyze@4

Publish Quality Gate Result task for SonarQube

  • task: SonarQubePublish@4)
    inputs:
    pollingTimeoutSec: ‘300’

The build is passed. While SonarQubeAnalyze, i am getting following error regarding C/C++/Objective-C though i have added analysis only for .Net solutions.

##[error]The only way to get an accurate analysis of C/C++/Objective-C files is by using the SonarSource build-wrapper and setting the property “sonar.cfamily.build-wrapper-output” or by using Clang Compilation Database and setting the property “sonar.cfamily.compile-commands”. None of these two options were specified.

If you don’t want to analyze C/C++/Objective-C files, then prevent them from being analyzed by setting the following properties:
sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-
sonar.objc.file.suffixes=-

Hey there.

There are probably some C/C++/Objective-C files in your project you aren’t aware of. If you don’t want to analyze these files, you should follow the instructions in the error message.

If you don’t want to analyze C/C++/Objective-C files, then prevent them from being analyzed by setting the following properties:
sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-
sonar.objc.file.suffixes=-

Hi Colin,

I have added sonar-project.properties file in root folder with below content, still issue is not resolved. Or do i need to add somewhere else?. Please suggest me if anything missed in below property file.

must be unique in a given SonarQube instance

sonar.projectKey=my:project

default: the C/C++/Objective-C plugin language sensor is disabled

sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-
sonar.objc.file.suffixes=-

A sonar-project.properties file can’t be read by the Scanner for .NET – I would suggest putting them in the “Additional analysis parameters” section of your SonarQubePrepare@4 build step.

Hi Colin,

Above solution worked form me. The issue is resolved by adding below properties under SonarQubePrepare@4
extraProperties: |
sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-
sonar.objc.file.suffixes=-

Thanks for your support

1 Like