Sonnar scanner using wrong base dir

We are using GitHub Actions in our organization to integrate with Sonar Cloud.
We use the dotnet scanner.

We are reusing exactly the same action code among our repositories, nevertheless, in some of them we are getting the following warning: SCM provider autodetection failed. Please use “sonar.scm.provider” to define SCM of your project, or disable the SCM Sensor in the project settings.

Having a deeper look into sonar scanner logs, I’ve identified that the ones with this warning have wrong Base dir when compared with the ones working properly:

The faulty ones are like:
Base dir: /
and the correct ones are like:
Base dir: /home/runner/work/REPO_NAME/REPO_NAME

Hey there.

Good eye on the base directory.

The .NET Scanner tried to calculate this from here:

    /// Appends the sonar.projectBaseDir value. This is calculated as follows:
    /// 1. the user supplied value, or if none
    /// 2. the sources directory if running from TFS Build or XAML Build, or
    /// 3. the common path prefix of projects in case there's a majority with a common root, or
    /// 4. the .sonarqube/out directory.

Can you turn on DEBUG level logging for the .NET Scanner (/d:sonar.verbose=true) and check the logs to see how it’s being calculated?

Hi, thanks for your reply.

The debug logs show that it is going for approach 3:
Using longest common projects path as a base directory: '/'.

I realized that this seems to affect all the repositories with Azure Functions.
My bet is that I’m facing an issue similar to this one, or at the least the root cause is the same:
Project base path detection is wrong for Azure Functions projects · Issue #1309 · SonarSource/sonar-scanner-msbuild (

You’re ahead of me. :slight_smile:

So the solution would be to manually set /d:sonar.projectBaseDir= /home/runner/work/REPO_NAME/REPO_NAME or similar

I can confirm that if I pass /d:sonar.projectBaseDir="$(pwd)" it starts detecting SCM and correctly represents the paths on sonar.

Would be good if this could be fixed in a way that would avoid having to pass the property.

Nevertheless, thanks for your support

1 Like