Dotnet-sonnarscanner working folder is always c:\windows\.sonarqube

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    sonarqube onprem enterprise edition 9.9.3
    dotnet-sonarscanner nuget tool 9.0.0
    windows 10

  • how is SonarQube deployed: zip, Docker, Helm
    sonarqube is deployed as docker, on a k8s cluster.

  • what are you trying to achieve
    I am trying to run a sonarqube scan for C# code compilation. the entire file storage is on a network drive with UNC path (“\”). I am using the dotnet-sonarscanner /begin and dotnet-sonarscanner /end commands to “wrap” the compilation process (dotnet build command).

the compilation succeeds, but the sonarqube scanner uses the local c:\windows folder for all the processing it does. this causes:

  1. we are unable to run multiple code scans on the same machine in parallel.
  2. other compilation processes which have nothing to do with sonarqube are affected by the changes made in the c:\windows folder.
  • what have you tried so far to achieve this
    I tried changing the projectBaseDir parameter during the /begin command, but the result is the same.

log of /begin command is attached.

sonarqube_begin_with_verbose.txt (12.4 KB)

Hi,

What you want is to change is not the base directory, but the working directory. Unfortunately, the docs are explicit that the SonarScanner for .NET doesn’t honor the sonar.working.directory parameter.

However, those same docs also say that the working directory is created in the base directory.

And when looking at your log (thanks for providing a debug log to start with! :star_struck:) I was struck by your command:

08:49:09.706 C:\Windows>\\AAAAnt\HHHHHH\CCCCC_GGGGG_DevOps\Products\EEEE\sonarqube-test_47\no-FFFFF\sonarscanner\dotnet-sonarscanner begin ...

You’re invoking the scanner from C:\windows, making it your base directory. Analysis is premised on being invoked from the project root. Can you try cd-ing into the project root directory and invoking analysis from there?

 
Ann

Hi @ganncamp ,

thanks for the quick and useful reply.
the situation we are handling is a scenario where we create a “wrapper” for the compilation being executed by other people during the pipeline.
we are starting the “begin” and “end” command before and after the compilation sequence, but we have no control over the compilation itself.
this means the users running the compilation itself are able to run it from any working folder they want.
in addition, since the computers running the compilation are not dynamically created, but rather used all the time, by multiple compilation flows, it was decided to conduct all io in a network folder, using UNC paths.
what I would expect is a parameter to set the UNC path as the base working dir, the analysis dir, and all the rest of the processing done by the sonarscanner.
can you point me to some sort of solution?
I can provide any information you need.

Hi,

This seems related to SCAN4NET-152, but you’re not in Azure DevOps, are you?

 
Ann

Hi @ganncamp ,

No, we are not using Azure devops.
the log I sent if from an execution of the scan using jenkins, gitlab, and windows 10.
as mentioned before, is there more information which might help you? i’ll do my best to provide it.

Hi,

I didn’t think you were, but wanted to confirm. I’ve flagged this for the team.

 
Thx,
Ann

Hi @ganncamp

thanks!

in addition, we are now facing an issue where we are building solutions (.sln files) consisting of both C++ and C# code.
what is the best way to scan both languages during a single compilation? is it even possible?

Hi,

That sounds like a separate topic. We try to keep it to one topic per thread. Otherwise it can get messy, fast. If I’m right, that this is a different topic, can you create a new thread for it, please?

 
Thx,
Ann

Hi @amidar,

Unfortunately, I do not have a way to create a network drive to have a proper test set-up.
I have run a quick test on my local using a UNC path pointing at my PC e.g. ‘\\MY-PC\C$\dev\Playground’ and the scanner worked as intended.

I did get a warning:

"CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory."

but the scan executed and uploaded results properly.

This means ideally you should be able to write a script that would cd into the correct directory for both the begin and end step.

e.g. (please note that the begin, build, and end step all need to be called from the same location)

$originalDirectory = Get-Location

$targetDirectory = "\\UNC\Path\To\Your\Project"

Set-Location $targetDirectory

dotnet sonar-scanner begin ...

dotnet build

dotnet sonar-scanner end ...

If this does not work, could you please attach the verbose logs of both the begin and end step for the failed attempt?

Thanks