dotnet tool install --global dotnet-sonarscanner dotnet sonarscanner begin /k:"project-key" dotnet build <path to solution.sln> dotnet sonarscanner end
but when I exec command dotnet sonarscanner begin /k:"project-key"
Here is the result:
Could not execute because the specified command or file was not found.
Possible reasons for this include:
You misspelled a built-in dotnet command.
You intended to execute a .NET Core program, but dotnet-sonarscanner does not exist.
You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
You donāt run the scanner with the right command. Please check documentation
This should be: dotnet sonarscanner begin /k:<myProjectKey>
and not dotnet dotnet-sonarscanner begin /k:<myProjectKey>
Once you fixed your cmd line you may have another problem: Thereās a dotnet strange behaviour (a bug ?) that causes just installed tools to not be immediately accessible to run.
There are quite some posts on the internet about that, with a variety of solutions.
See https://github.com/dotnet/sdk/issues/8999 and https://github.com/dotnet/cli/issues/8369
You may try the recipes given there.
I could also reproduce a similar problem in a docker container.
I had to set the $PATH env variable before the scanner could be used