SonarQube not showing any c# analysis

Hello,

dear community,

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
  • MsBuild.exe .\Gc.Ws.Service.Scheduler.sln /t:Rebuild /v:diag > msbuild.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

Best regards,
Filip

@filipveskrna thanks for the logs.

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).

Thanks.

Hello @duncanp ,

thank you for the reply.

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.

Best regards,
Filip

Hi @filipveskrna,

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.

Hello @duncanp ,

all right, here is the file:
SonarQubeAnalysisConfig.zip (2.6 KB)

Hi @filipveskrna,

Interesting.

This is an excerpt from your xml file:

        <AnalyzerPlugin Key="csharp" Version="8.40.0.48530" StaticResourceName="SonarAnalyzer-8.40.0.48530.zip">
          <AssemblyPaths>
            <Path>C:\Users\fvekrna\AppData\Local\Temp\.sonarqube\resources\8\THIRD-PARTY-NOTICES.txt</Path>
          </AssemblyPaths>

This is an excerpt from a file where analysis is working:

        <AnalyzerPlugin Key="csharp" Version="8.29.0.36737" StaticResourceName="SonarAnalyzer-8.29.0.36737.zip">
          <AssemblyPaths>
            <Path>C:\Users\john.smith\AppData\Local\Temp\.sonarqube\resources\0\Google.Protobuf.dll</Path>
            <Path>C:\Users\john.smith\AppData\Local\Temp\.sonarqube\resources\0\Newtonsoft.Json.dll</Path>
            <Path>C:\Users\john.smith\AppData\Local\Temp\.sonarqube\resources\0\SonarAnalyzer.CFG.dll</Path>
            <Path>C:\Users\john.smith\AppData\Local\Temp\.sonarqube\resources\0\SonarAnalyzer.CSharp.dll</Path>
            <Path>C:\Users\john.smith\AppData\Local\Temp\.sonarqube\resources\0\SonarAnalyzer.dll</Path>
            <Path>C:\Users\john.smith\AppData\Local\Temp\.sonarqube\resources\0\THIRD-PARTY-NOTICES.txt</Path>
          </AssemblyPaths>
        </AnalyzerPlugin>
...

For some reason your config is missing all of the analyzer binary files. I’ll have a look into what might cause this and get back to you.

@filipveskrna,

Here’s an excerpt from the begin log you sent me:

16:15:09.219  Local analyzer cache: C:\Users\fvekrna\AppData\Local\Temp\.sonarqube\resources
...
16:15:09.263  Provisioning analyzer assemblies for cs...
16:15:09.265  Installing required Roslyn analyzers...
16:15:09.267  Processing plugin: csharp version 8.40.0.48530
16:15:09.365  Cache hit: using plugin files from C:\Users\fvekrna\AppData\Local\Temp\.sonarqube\resources\8
16:15:09.366  Processing plugin: vbnet version 8.40.0.48530
16:15:09.367  Cache hit: using plugin files from C:\Users\fvekrna\AppData\Local\Temp\.sonarqube\resources\9

So, the scanner thinks the files have already been downloaded and skips downloading them again.

A couple of questions:

  • do the folders under C:\Users\fvekrna\AppData\Local\Temp\.sonarqube\resources\ actually contain any assemblies?
  • if not, what happens if you delete that folder and try running the analysis again?