I’ve just registered for the 14-day trial for SonarCloud and cannot get past the initial setup of building from a GitHub Action.
My code is a .NET 6 C# solution, with a Web API and several Azure Functions.
I am using the following command in the GitHub Action template provided by SonarCloud for the build step:
dotnet build MySolution.sln
But I am getting several warnings, and finally an error at the end indicating “Generation of the sonar-properties file failed. Unable to complete the analysis.”, which I think trace back to: “Could not determine a suitable project base directory.”
However in case there is more going on that I don’t understand, here are some snippets of the messages:
WARNING: The following projects do not have a valid ProjectGuid and were not built using a valid solution (.sln) thus will be skipped from analysis...
C:\Users\runneradmin\AppData\Local\Temp\ptkwfgfq.hz1\WorkerExtensions.csproj, C:\Users\runneradmin\AppData\Local\Temp\nlombzhz.ucn\WorkerExtensions.csproj
WARNING: Duplicate ProjectGuid: "00000000-0000-0000-0000-000000000000". The project will not be analyzed. Project file: "c:\users\runneradmin\appdata\local\temp\ptkwfgfq.hz1\workerextensions.csproj"
WARNING: Duplicate ProjectGuid: "00000000-0000-0000-0000-000000000000". The project will not be analyzed. Project file: "c:\users\runneradmin\appdata\local\temp\nlombzhz.ucn\workerextensions.csproj"
WARNING: Could not determine a suitable project base directory. Using the fallback D:\a\[solutionpath]\.sonarqube\out . Make sure that all dependencies of your project are available on your filesystem, as this fallback may lead to no result being show after the analysis.
WARNING: File 'D:\a\[solutionpath]\[somefile].cs' is not located under the root directory 'D:\a\[solutionpath]\.sonarqube\out' and will not be analyzed.
WARNING: File 'D:\a\[solutionpath]\[somefile].cs' is not located under the root directory 'D:\a\[solutionpath]\.sonarqube\out' and will not be analyzed.
WARNING: File 'D:\a\[solutionpath]\[somefile].cs' is not located under the root directory 'D:\a\[solutionpath]\.sonarqube\out' and will not be analyzed.
WARNING: File 'D:\a\[solutionpath]\[somefile].cs' is not located under the root directory 'D:\a\[solutionpath]\.sonarqube\out' and will not be analyzed.
WARNING: File 'D:\a\[solutionpath]\[somefile].cs' is not located under the root directory 'D:\a\[solutionpath]\.sonarqube\out' and will not be analyzed.
WARNING: File 'D:\a\[solutionpath]\[somefile].cs' is not located under the root directory 'D:\a\[solutionpath]\.sonarqube\out' and will not be analyzed.
WARNING: File 'D:\a\[solutionpath]\[somefile].cs' is not located under the root directory 'D:\a\[solutionpath]\.sonarqube\out' and will not be analyzed.
WARNING: File 'D:\a\[solutionpath]\[somefile].cs' is not located under the root directory 'D:\a\[solutionpath]\.sonarqube\out' and will not be analyzed.
... several of these for what appears to be every file ...
WARNING: File 'D:\a\[solutionpath]\[somefile].cs' is not located under the root directory 'D:\a\[solutionpath]\.sonarqube\out' and will not be analyzed.
WARNING: File 'D:\a\[solutionpath]\[somefile].cs' is not located under the root directory 'D:\a\[solutionpath]
No analysable projects were found. SonarCloud analysis will not be performed. Check the build summary report for details.
Generation of the sonar-properties file failed. Unable to complete the analysis.
Error: Process completed with exit code 1.
I’m aware that currently you either need to build with a Solution file or otherwise add ProjectGuids to every project to get rid of the ProjectGuid issues, hence I am building with the Solution file. The two “WorkerExtension.csproj” warnings I believe come from auto-generated projects from the Microsoft Azure Function projects (we have two of them).
Edit:
I also tried doing a dotnet restore before the dotnet build solution.sln but that does not help either.
I should note that I do see a lot of the SonarAnalyzer warnings as the project builds, so it seems that the scan is happening? Just the results are not being picked up?
Also for what it’s worth, I was able to reproduce this without my own code by doing the following:
Use Visual Studio 2022 to create a new .NET 6, Isolated-Process Azure Function. The basic HTTP-trigger one is fine.
Create a new GitHub repo and commit the solution and project and template code files as-is (i.e. commit the files the project template produces as-is, make no code changes).
Setup a GitHub Action using the provided build.yml template in SonarCloud using dotnet build [solutionname].sln as the build command.
This produces:
SonarScanner for MSBuild 5.7.2
Using the .NET Core version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
00:03:50.931 Updating build integration targets...
00:03:51.494 Fetching analysis configuration settings...
00:03:52.33 Provisioning analyzer assemblies for cs...
00:03:52.331 Installing required Roslyn analyzers...
00:03:53.383 Provisioning analyzer assemblies for vbnet...
00:03:53.383 Installing required Roslyn analyzers...
00:03:53.417 Pre-processing succeeded.
Microsoft (R) Build Engine version 17.2.0+41abc5629 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
Restored D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\AzFuncForCodeScanning\AzFuncForCodeScanning.csproj (in 9.91 sec).
AzFuncForCodeScanning -> D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\AzFuncForCodeScanning\bin\Debug\net6.0\AzFuncForCodeScanning.dll
Sonar: (AzFuncForCodeScanning.csproj) Project processed successfully
Determining projects to restore...
Restored C:\Users\runneradmin\AppData\Local\Temp\djzrn452.xuj\WorkerExtensions.csproj (in 48.14 sec).
WorkerExtensions -> C:\Users\runneradmin\AppData\Local\Temp\djzrn452.xuj\buildout\Microsoft.Azure.Functions.Worker.Extensions.dll
D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\.sonarqube\bin\targets\SonarQube.Integration.targets(369,5): warning : The project does not have a valid ProjectGuid. Analysis results for this project will not be uploaded. Project file: C:\Users\runneradmin\AppData\Local\Temp\djzrn452.xuj\WorkerExtensions.csproj [C:\Users\runneradmin\AppData\Local\Temp\djzrn452.xuj\WorkerExtensions.csproj]
Sonar: (WorkerExtensions.csproj) Project processed successfully
00:05:06.382 No analysable projects were found. SonarCloud analysis will not be performed. Check the build summary report for details.
Build succeeded.
D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\.sonarqube\bin\targets\SonarQube.Integration.targets(369,5): warning : The project does not have a valid ProjectGuid. Analysis results for this project will not be uploaded. Project file: C:\Users\runneradmin\AppData\Local\Temp\djzrn452.xuj\WorkerExtensions.csproj [C:\Users\runneradmin\AppData\Local\Temp\djzrn452.xuj\WorkerExtensions.csproj]
1 Warning(s)
0 Error(s)
Time Elapsed 00:01:12.45
SonarScanner for MSBuild 5.7.2
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
00:05:06.318 00:05:06.318 WARNING: The following projects do not have a valid ProjectGuid and were not built using a valid solution (.sln) thus will be skipped from analysis...
C:\Users\runneradmin\AppData\Local\Temp\djzrn452.xuj\WorkerExtensions.csproj
00:05:06.363 00:05:06.363 WARNING: Could not determine a suitable project base directory. Using the fallback D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\.sonarqube\out . Make sure that all dependencies of your project are available on your filesystem, as this fallback may lead to no result being show after the analysis.
00:05:06.381 00:05:06.381 WARNING: File 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\AzFuncForCodeScanning\Function1.cs' is not located under the root directory 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\.sonarqube\out' and will not be analyzed.
00:05:06.381 00:05:06.381 WARNING: File 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\AzFuncForCodeScanning\Program.cs' is not located under the root directory 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\.sonarqube\out' and will not be analyzed.
00:05:06.381 00:05:06.381 WARNING: File 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\AzFuncForCodeScanning\obj\Debug\net6.0\AzFuncForCodeScanning.GlobalUsings.g.cs' is not located under the root directory 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\.sonarqube\out' and will not be analyzed.
00:05:06.381 00:05:06.381 WARNING: File 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\AzFuncForCodeScanning\obj\Debug\net6.0\.NETCoreApp,Version=v6.0.AssemblyAttributes.cs' is not located under the root directory 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\.sonarqube\out' and will not be analyzed.
00:05:06.381 00:05:06.381 WARNING: File 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\AzFuncForCodeScanning\obj\Debug\net6.0\AzFuncForCodeScanning.AssemblyInfo.cs' is not located under the root directory 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\.sonarqube\out' and will not be analyzed.
00:05:06.381 00:05:06.381 WARNING: File 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\AzFuncForCodeScanning\.gitignore' is not located under the root directory 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\.sonarqube\out' and will not be analyzed.
00:05:06.382 00:05:06.382 WARNING: File 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\AzFuncForCodeScanning\host.json' is not located under the root directory 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\.sonarqube\out' and will not be analyzed.
00:05:06.382 00:05:06.382 WARNING: File 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\AzFuncForCodeScanning\Properties\launchSettings.json' is not located under the root directory 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\.sonarqube\out' and will not be analyzed.
00:05:06.382 00:05:06.382 WARNING: File 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\AzFuncForCodeScanning\Properties\serviceDependencies.json' is not located under the root directory 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\.sonarqube\out' and will not be analyzed.
00:05:06.382 00:05:06.382 WARNING: File 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\AzFuncForCodeScanning\Properties\serviceDependencies.local.json' is not located under the root directory 'D:\a\AzFuncForCodeScanning\AzFuncForCodeScanning\.sonarqube\out' and will not be analyzed.
00:05:06.382 Generation of the sonar-properties file failed. Unable to complete the analysis.
00:05:06.387 Post-processing failed. Exit code: 1
Error: Process completed with exit code 1.
I do see this in the “Post Cache SonarCloud packages” step, does this indicate anything problematic?
Post job cleanup.
C:\Windows\System32\tar.exe -cz -f D:\a\_temp\46417b3a-406c-4f4f-92c0-333ad59c6d75\cache.tgz -C C:\Users\runneradmin\sonar\cache .
tar.exe: could not chdir to 'C:\Users\runneradmin\sonar\cache'
Warning: Tar failed with error: The process 'C:\Windows\System32\tar.exe' failed with exit code 1. Ensure BSD tar is installed and on the PATH.
Outside of that, to fix the build issue I had, it seems I need to manually specify the sonar.projectBaseDir setting for the dotnet-sonarscanner begin command. It should be set to the location where the source code gets checked-out to. I’m not sure why it isn’t picked up by default.
However for now I opted to do something like this in the “Build and analyze” step:
Essentially, I grab the current directory and pass that to the projectBaseDir setting.
Not sure why something like this isn’t at least pointed out directly in the SonarCloud GitHub Action template, as it doesn’t provide a great first time experience.