We have one solution with .net and C++ projects, and dependencies between them. Is SonarQube supports this with SonarScanner.MSBuild.exe?

We have one solution with .net and C++ projects, and dependencies between them. Is SonarQube supports this with SonarScanner.MSBuild.exe?

When I tried to build the .NET & C++ projects through MSBuild I’m getting error BC30002: Variable not defined error.

Could you please help me on this.

Hello @SrinivasP,

Yes this is possible. This is a common mix of languages in the .Net world.
See this section of the C/C++ documentation. That should help you. If you still have questions, get back to this thread.

Olivier

I have followed the same times and still seeing the issues. The Build commands below.

SonarScanner.MSBuild.exe begin /k:xxxxx /d:sonar.host.url=xxx.xx/d:sonar.verbose=true /d:sonar.login=xxxx /d:sonar.cfamily.build-wrapper-output=“build_wrapper_output_directory”
build-wrapper-win-x86-64.exe --out-dir build_wrapper_output_directory

MSBuild.exe “MPBuild.sln” /t:Clean /t:Build /p:Configuration=Debug /p:Platform=“Any CPU” /p:TargetProfile=Local

Hello,

I am afraid you have not read carefully enough the documentation link I send.
You don’t run MSBuild.exe as it should (look at the build wrapper !)

Olivier

In the given links suggets to execute the MSbuild and didn’t mention that don’t execute the MSBuild.

https://docs.sonarqube.org/latest/analysis/languages/cfamily/#header-7

SonarScanner.MSBuild.exe begin /k:"cs-and-cpp-project-key" /n:"My C# and C++ project" /v:"1.0" /d:sonar.cfamily.build-wrapper-output="build_wrapper_output_directory"
build-wrapper-win-x86-64.exe --out-dir build_wrapper_output_directory MSBuild.exe /t:Rebuild
SonarScanner.MSBuild.exe end

The given link mentions that you must run MSBuild “wrapped” with build wrapper.

# Run scanner begin step and
# pass a build wrapper output directory of your choice (local temp directory)
SonarScanner.MSBuild.exe begin /k:xxxxx /d:sonar.host.url=xxx.xx/d:sonar.verbose=true /d:sonar.login=xxxx /d:sonar.cfamily.build-wrapper-output=“build_wrapper_output_directory”

# Run MSBuild with build-wrapper wrapping around it
# and pass same output directory to build wrapper
build-wrapper-win-x86-64.exe --out-dir build_wrapper_output_directory MSBuild.exe “MPBuild.sln” /t:Clean /t:Build /p:Configuration=Debug /p:Platform=“Any CPU” /p:TargetProfile=Local

# Run Scanner end step
SonarScanner.MSBuild.exe end 

If that does not work as expected for some reason, please attach a file with the full console output of the above 3 commands for investigation

Olivier

@OlivierK

I’m not understanding how to do MSBuild “wrapped” with build wrapper. could you please help me on this.

Hello,

Your normal command to build your project is:
MSBuild.exe “MPBuild.sln” /t:Clean /t:Build /p:Configuration=Debug /p:Platform=“Any CPU” /p:TargetProfile=Local

To wrap it with build wrapper, you need to “prepend” your command with build-wrapper-win-x86-64.exe --out-dir build_wrapper_output_directory. This will run build-wrapper that will do a few preparation things and then execute your following build command as usual (and collect some information (that you don’t need to look at) in the build_wrapper_output_directory in the process)

So in your case you need to run:
build-wrapper-win-x86-64.exe --out-dir build_wrapper_output_directory MSBuild.exe “MPBuild.sln” /t:Clean /t:Build /p:Configuration=Debug /p:Platform=“Any CPU” /p:TargetProfile=Local

Olivier

I Tried above method and no luck I’m getting error BC30002: Variable not defined error for C++ projects.

Does you project compiles when you build it without SonarScanner and wrapper ?
This seems to me like a compilation problem, not a SonarQube problem.
I forgot to mention this implicit prerequisite that your code should compile before being able to analyze it !

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.