I am having problems with running an analysis and afterwards with the results on the SonarQube server. We have a .NET project. The whole analysis runs locally and the SonarQube instance runs on the embedded database. This is intentional.
Which versions am I using
SonarQube Community Edition Version 9.5 (build 56709) run locally
SonarScanner for MSBuild 5.7.2 run from PowerShell 7.2.5 terminal
What am I trying to achieve
I would expect, that after the end phase of the analysis process, there will be analysis results of the .cs files as well as code issues etc. At the moment all .cs files in the “Code” section are shown having no lines of code.
What have I tried so far to achieve this
running a fresh deployment of SonarQube
fresh installation of Visual Studio 2019
carefully checking, that Path variables are set to the correct/desired versions
different versions of MSBuild (16.11.2.50704, 17.3.0.37102)
different versions of Java (OpenJDK), currently updated to JDK 17.0.4 from Oracle
The SonarScanner analysis is being run as following:
SonarScanner.MSBuild.exe begin /k:"svc-Scheduler" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="sqp_xxx" /d:sonar.verbose=true /d:sonar.sourceEncoding=UTF-8 > sonarscanner.begin.log
SonarScanner.MSBuild.exe end /d:sonar.login="sqp_xxx" > sonarscanner.end.log
After I have searched and read already existing topics at the sonar community, I have most likely found relevant log messages. Both of them are output from the end phase:
DEBUG: Project 'svc-Scheduler': Property missing: 'sonar.cs.analyzer.projectOutPaths'. No protobuf files will be loaded for this project.
WARN: No protobuf reports found. The C# files will not have highlighting and metrics. You can get help on the community forum: https://community.sonarsource.com
Unfortunately I was unable to move any further. Does anybody know, where the problem could be?
If necessary, I could provide the diagnostic or verbose logs from all the steps. Preferably via a private channel
Could you confirm that issues are being reported correctly in SonarQube?
There are a lot of entries in log for the end step like the following: 16:22:07.419 DEBUG: Project [redacted]': Analyzer working directory does not exist: '[redacted]\.sonarqube\out\0\output-cs'. Analyzer results won't be loaded from this directory.
This suggests the analzyers that calculate the metrics are not being executed.
To test this, could you try adding /p:reportanalyzer=true to the MSBuild step please? (see here for more info).
As you advised, I have run the build phase with the suggested parameter. The log does not contain any string “SonarAnalyzer” so I guess, that the report analyzer is not being executed.
In case you need, the enriched log from msbuild is here: msbuild.zip (7.1 MB)
Do you have any tips how I could make the analyzer being executed when it should.
You’re right, the Sonar Roslyn analyzers are not being picked up and passed to the compiler. However, from the log of the begin step, it does look like they are being downloaded from the server.
There is an MSBuild target called GetAnalyzerSettings. This takes a list of the analyzers configured in your MSBuild project file (i.e. the non-Sonar analyzers) and adds the Sonar analyzers. The task produces an ItemGroup called SQAnalyzerFilePaths, which is the full list of analyzers to run. For some reason, the Sonar analyzers have not been added to that list.
Could you share the D:\NPO-FMS\source\svc\Scheduler\.sonarqube\conf\SonarQubeAnalysisConfig.xml file please? It is one of the other inputs used by the GetAnalyzerSettings task, and should contain the full paths to the Sonar Roslyn analyzers to use.