Sonarcloud analysis steps fails for a .net project containing c++ files

Receiving the below error for the SonarCloud analysis step, I dont want to exclude the c++ files, I need them analyzed as well along with the C# files.

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 “” 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=-

It’s not an error so much as it’s instructions!

Have you followed the tutorial in SonarCloud for analyzing C/C++/Objective-C files?

For an already configured project, you can find the tutorials under Administration > Analysis Method
Screenshot 2023-08-24 at 10.22.46

Hi Colin,

Thanks for the reply. I have taken a look at the documentation and it wasnt clear for my particular scenario. Tried a few things but still having issues.

Do you have any example yaml file setup and further steps to get a solution containing both c++ and C# files in it. Where the build runs in a physical agent.

This is how I setup the yaml on my end.

- task: SonarCloudPrepare@1
  displayName: Prepare analysis on SonarCloud
    SonarCloud: 'SonarCloud'
    organization: 'md'
    scannerMode: 'CLI'
    configMode: file
    projectKey: 'MIQe'
    projectName: 'IQe'
    extraProperties: |
      # sonar.sslVerificationMode=NONE  # Disable SSL verification
      # sonar.exclusions=**/*.cpp,**/*.h
      # sonar.c.file.suffixes=-
      # sonar.cpp.file.suffixes=-
      # sonar.objc.file.suffixes=-
- powershell: |
    curl ${{variables.BUILD_WRAPPER_DOWNLOAD_URL}} -o $HOME\.sonar\
    unzip -o $HOME\.sonar\ -d $HOME\.sonar\
  displayName: Download and install build wrapper
- powershell: |
    $path = vswhere -latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe | select-object -first 1
    & "$HOME\.sonar\build-wrapper-win-x86\build-wrapper-win-x86-64.exe" --out-dir build_wrapper_output_directory $path $(Build.SourcesDirectory)/IQe/IQe.sln /p:Platform=$(buildPlatform) /p:Cofiguration=$(buildConfiguration) /t:rebuild /nodeReuse:false
  workingDirectory: .
  displayName: Build in build-wrapper

Any help would be much appreciated.

Hey there.

Where’s the SonarCloudAnalyze task?

And, I think this example will help you (you can ignore the coverage bit if it’s not interesting to you)

Thanks for the reply Colin. I made some progress with your help, but I am still running into issues with the SonarCloudAnalyze phase.

14:53:33.431 INFO: ------------------------------------------------------------------------


14:53:33.432 INFO: ------------------------------------------------------------------------

14:53:33.432 INFO: Total time: 5.867s

14:53:33.469 INFO: Final Memory: 9M/34M

14:53:33.470 INFO: ------------------------------------------------------------------------

##[error]14:53:33.470 ERROR: Error during SonarScanner execution

##[debug]Processed: ##vso[task.logissue type=error;]14:53:33.470 ERROR: Error during SonarScanner execution

14:53:33.470 ERROR: Error during SonarScanner execution

##[error]java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.ProjectLock

at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(

at org.picocontainer.DefaultPicoContainer.getComponent(

at org.sonar.core.platform.ComponentContainer.getComponentByType(

at org.sonar.scanner.scan.ProjectScanContainer.doBeforeStart(

at org.sonar.core.platform.ComponentContainer.startComponents(

at org.sonar.core.platform.ComponentContainer.execute(

at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(

at org.sonar.core.platform.ComponentContainer.startComponents(

at org.sonar.core.platform.ComponentContainer.execute(

at org.sonar.batch.bootstrapper.Batch.doExecute(

at org.sonar.batch.bootstrapper.Batch.execute(

at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(

at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHa

at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(

… 34 more

Caused by: You must define the following mandatory properties for ‘Unknown’: sonar.projectKey

##[debug]Exit code 1 received from tool ‘C:\agent\vsts-agent-win-x64-2.188.3_work_tasks\SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1\1.41.0\sonar-scanner\bin\sonar-scanner.bat’

##[debug]STDIO streams have closed for tool ‘C:\agent\vsts-agent-win-x64-2.188.3_work_tasks\SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1\1.41.0\sonar-scanner\bin\sonar-scanner.bat’

##[debug]task result: Failed

This is my SonarCloudAnalyze step

- task: SonarCloudAnalyze@1
  displayName: 'Run SonarCloud analysis'
    jdkversion: 'JAVA_HOME'

This is my properties file


Properties that will be shared amongst all modules


SQ standard properties


Properties specific to the C and C++ analyzer:

Hey Colin,

I managed to get around the above issue by updating the sonar properties file that resides in the folder where sonar scanner resides. Now the sonarAnalyze step works

But then I ran into the below… guessing I would have to update my subscription for this?

##[error][SQ] Task failed with status FAILED, Error message: This analysis will make your organization ‘md’ to reach the maximum allowed lines limit (having 559549 lines).

Congrats on all the progress you’ve made.

Yes – it sounds like your project is pretty big. And – you can adjust the analysis scope if you need to at least get some of the results, or to exclude files you don’t need analyzed at all.