Analysing a project which has C# and C++ in its solution

Hi,

I am analysing a Project Solution made of C++ and C#. As instructed in Building on Windows with MSBuild a Solution made of a mix of C++ and C# I have performed the analysis with below commands:

SonarQube Scanner for MSBuild “begin” step
Command: SonarQube.Scanner.MSBuild.exe begin /k:“cs-and-cpp-project-key” /n:“My C# and C++ project” /v:“1.0” /d:sonar.cfamily.build-wrapper-output=“bw_output”
Result: Pre-processing is successful

Adding execution of Build Wrapper to normal MSBuild build command:
Command: build-wrapper-win-x86-64.exe --out-dir bw_output MSBuild.exe /t:Rebuild
Result: Build is successful

SonarQube Scanner for MSBuild “end” step to complete the analysis
Command: SonarQube.Scanner.MSBuild.exe end
Result: Post-processing is failing with the below error

ERROR: Error during SonarQube Scanner execution
ERROR: Unable to extract version of Microsoft Compiler
ERROR:
The SonarQube Scanner did not complete successfully
13:18:03.858 Creating a summary markdown file…
13:18:03.874 Post-processing failed. Exit code: 1

SonarQube Versions Used:
Sonarqube-7.3 Enterprise Edition (Trial License)
SonarCFamily 5.1.1 Plugin
build-wrapper-win-x86
sonar-scanner-msbuild-4.3.1.1372-net46
Visual Studio Professional 2015

How do I resolve this error and perform the complete analysis?

Thanks,
Madhuvanthi Teli

Hello,

There used to be a similar issue with old versions of the build wrapper. Could you share the version you are using? (it’s at the top of the build-wrapper.log file)

Thank you!

Hello,

Thank you for the response. I am using build-wrapper, version 5.1 (win-x86-64) and SonarCFamily 5.1.1 Version plugin.

When i run the above commands in command prompt, i get below error in build-wrapper.log file

cmd_error_log

When i run the above commands in Developer Command Prompt for VS2015, i get below error in build-wrapper.log file

VSDev_cmd_log

In both cases, post-process is failing with the same error: Unable to extract the version of Microsoft Compiler.

Thanks,
Madhuvanthi Teli

Hello,

It would be interesting to know what is in the stderr section of the log (this is why providing the log always allows less back and forth than providing some screenshots of it).

But from what is currently displayed, it looks like you are not really using the Microsoft C++ compiler, but some kind of wrapper above it, which is probably the reason for the issue…

Hi,

Please find attached the contents of build-wrapper.log and build-wrapper-dump.json files.

build-wrapper-log.txt (2.4 MB)

build-wrapper-dump.txt (1.2 MB)

Yes. I am using our own compiler instead of Microsoft Compiler. Is SonarCFamily not supporting our compiler?

Regards,
Madhu

The list of the compilers we support is on https://www.sonarsource.com/products/codeanalyzers/sonarcfamilyforcpp.html

If your custom compiler fully mimics the interface of Microsoft compiler, we will not see any difference, and the analysis might work, even if it’s not supported.

Here, this is not the case. More specifically, if you run Microsoft cl.exe with no parameters, it will output on stderr something like (mine is in French, but you will have a similar string in all languages):

Compilateur d'optimisation Microsoft (R) C/C++ version 19.15.26730 pour x86
Copyright (C) Microsoft Corporation. Tous droits réservés.

In your compiler, stderr is empty when cl.exe is invoked that way.

If your compiler is close enough to Microsoft compiler, another option you could have is to have a build configuration that uses it, instead of your custom compiler, and use this configuration for analysis, even if you can’t use it for production code.

Hi,

Goal is make sonarqube use the right compiler from the Configuration & Platform details.

I have used project details as below:

build-wrapper-win-x86-64.exe --out-dir bw_output MSBuild.exe /t:Rebuild /p:Configuration=Release /p:Platform=STM32F1 project_solution_name.sln
(I have used configuration details like above for analysing a C# project and it worked fine)

But, sonarqube is pointing to a default Compiler (with error: tci2010: Value cannot be null.\r\nParameter name: path1) and not the right compiler for the STM32F1 Platform in MSBuild.

Is the above way of giving cnfiguration details in the build command right?
If not, how can i make sonarqube use the correct compiler from the configuration Details?

Thanks & Regards,
Madhu

Hi @MadhuTeli,

did you manage to solve your issue?

Hi,

Yes. I could find a solution to this. The Problem was with our own compiler. The compiler is configured in such a way that the output of cl.exe wrapper is only in ‘stdout’ section and ‘stderr’ remains empty. I did a small workaround to copy the version of C/C++ compiler in ‘stderr’ from ‘stdout’ section. Then it worked as exepected.

Thanks for your support.

Regards,
Madhu

2 Likes

Hi @MadhuTeli,

great, thank you for your answer.