-
Notifications
You must be signed in to change notification settings - Fork 364
sonar.cxx.msbuild.reportPaths
The cxx plugin supports reading the MSBuild .LOG file to automatically extract the required macros (sonar.cxx.defines) and include directories (sonar.cxx.includeDirectories).
The Predefined Macros matching the Visual Studio version are generated and further definitions are read from the .LOG file.
- Link to the tool page: https://github.com/dotnet/msbuild, https://visualstudio.microsoft.com/
- Supporting Visual Studio 2010 to 2019.
-
Platform toolset
- Visual Studio 2010: v100
- Visual Studio 2012: v110
- Visual Studio 2013: v120
- Visual Studio 2015: v140
- Visual Studio 2017: v141
- Visual Studio 2019: v142
- Visual Studio 2022: v143 (not supported)
-
Platform toolset
A .LOG file is generated when MSBuild is executed. It is the easiest to redirect stdout to a LOG file:
Hint: This function is enabled only if the .LOG generated during compilation contains sufficient information. MSBuild verbosity must be set to
detailed
ordiagnostic
!
msbuild.exe /v:Detailed MySolution.sln > MSBuild.log
Advanced MSBuild example doing a project rebuild and write to MSBuild.log
:
rem VS2019 Enterprise
call "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
MSBuild.exe example.proj /t:rebuild /p:Configuration=Release;WarningLevel=3 /fileLogger /fileLoggerParameters:WarningsOnly;LogFile=MSBuild.log;Verbosity=detailed;Encoding=UTF-8
If the tool was executed successfully, a report like the example below should be generated:
Build started 26.01.2021 14:16:53.
Logging verbosity is set to: Detailed.
1>Project "D:\Sample\Sample.vcxproj" on node 3 (Rebuild target(s)).
...
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\string.h(107,17): warning C4995: 'memcpy': name was marked as #pragma deprecated [D:\Sample\Sample.vcxproj]
1>D:\Sample\File1.cpp(44,89): warning C4838: conversion from 'uint' to 'uint8' requires a narrowing conversion [D:\Sample\Sample.vcxproj]
1>D:\Sample\File2.cpp(7,1): warning C4100: 'result_listener': unreferenced formal parameter [D:\Sample\Sample.vcxproj]
1>D:\Sample\File1.cpp(414,41): warning C4239: nonstandard
...
- First check if the file extensions read in by the cxx plugin are set (sonar.cxx.file.suffixes).
- Set the analysis parameter
sonar.cxx.msbuild.reportPaths
in the configuration filesonar-project.properties
of your project. The Report Paths link describes the configuration options. - Normally the File Encoding is UTF-8. Use the parameter sonar.cxx.msbuild.encoding to use another one.
-
Narrowing the Focus gives more hints how to include and exclude files. At least
sonar.sources
must match the contents of the database. - Execute the SonarScanner to transfer the project with the report to the SonarQube Server.
If the includes and macros come from multiple sources, they are processed in the following order:
- Definitions assigned to a file.
- Global definitions.
- Definitions from
sonar-project.properties
. - Predefined Macros
sonar.cxx.includeDirectoris=1,2,3 // searching files in directories from left to right
sonar.cxx.defines=1,2,3,4 // first macro definition found is used, search from left to right
Sample for sonar-project.properties:
sonar.cxx.msbuild.reportPaths=MSBuild.log
sonar.cxx.msbuild.encoding=UTF-8