Dotnet-sonarscanner - v8.0.0 - failing to identify project root directory

Template for a good new topic, formatted with Markdown:

  • ALM used (GitHub)
  • CI system used (GitHub actions)
  • Scanner command used when applicable (..sonar\scanner\dotnet-sonarscanner begin … end)
  • Languages of the repository (c#)
  • Error observed When using dotnet scanner - 8.0.0
Could not find a part of the path 'C:\home\runner\_work\<Repo_path>\bin\Release\net8.0'.
SonarScanner for MSBuild 8.0
Using the .NET Core version of the Scanner for MSBuild 
  • Steps to reproduce
  1. Upgrade the sonar scanner to 8.0.0
  2. Execute the dotnet scan via command ‘..sonar\scanner\dotnet-sonarscanner begin’ including all the project properties
  3. The scan works but the analysis publish fails since the scanner is unable to find the analysis report and falling to use based directory as C:\home\runner_work<repo_path>.sonarqube, which is incorrect
  • Potential workaround
  1. The work around is to switch back to version 7.1.1 using command ‘dotnet tool install dotnet-sonarscanner --tool-path ..sonar\scanner --version 7.1.1’
  2. Another work around is to set the project base dir(/d:sonar.projectBaseDir) to absolute path of the repo path

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hey there,

Could you tell me where you are calling the scanner from?
Meaning, what’s the current working directory of the scanner begin and end command?

Also, could you please share your logs with verbosity enabled?
Specifically, set /d:sonar.verbose=true in the begin step.

Thanks in advance.

Hi @suhas-arcadis,

In v8 we modified the root path detection to work in the following way:

Unless overridden by the user (sonar.projectBaseDir is provided by the user, TF_BUILD_SOURCESDIRECTORY env, or BUILD_SOURCESDIRECTORY env), the sonar.projectBaseDir property is set to the current directory (the folder from where the scanner was executed). If the user executes the scanner from a folder that does not contain the source code (the analyzed projects are not found in the current directory or in a nested folder), there is a fallback mechanism in place that looks for .csproj files linked in the .sln and tries to compute the common root directory.

Until we better understand the root cause of your issue, I recommend setting the /d:sonar.projectBaseDir property as a workaround (as you already mentioned) since this will allow the usage of the latest version of the scanner.

To better understand why the automatic detection does not work, could you please share with us:

  • the logs in verbose mode (as my colleague mentioned)
  • if the scanner is executed from the sources folder or from another directory
  • what is the folder structure? are the csproj files placed in folders that have the only common root the / folder?

The logs in the verbose mode will help us a lot to understand the root cause and provide support for your workflow.

Thanks,
Costin

Hi @costin.zaharia - Find the requested details:

  • verbose logs attached
  • sources directory
  • The solution file(.sln) exists in the root dir. The source files exist in the individual component folders along with .csproj file within that
    sq_verbose.txt (51.5 KB)
1 Like

Hey there,
Could you please send us logs from a successful dotnet build?
These logs seem to fail during the build because of:

C:\home\runner\_work\Global-EIA-backend\Global-EIA-backend\EIA.Database\EIA.Database.sqlproj(55,3): error MSB4278: The imported file "$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" does not exist and appears to be part of a Visual Studio component. This file may require MSBuild.exe in order to be imported successfully, and so may fail to build in the dotnet CLI. 

…which does not seem related to the scanner.

Thanks!