Error dotnet tool install --global dotnet-sonarscanner

Viewed 959

Just trying to install Sonarqube without docker image, locally:

-- dotnet tool install --global dotnet-sonarscanner C:\Program Files\dotnet\sdk\6.0.200\NuGet.targets(130,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/tPointAgileOrg/tPoint/_packaging/tPoint/nuget/v3/index.json. [C:\Users\Anri_Kezeroti\AppData\Local\Temp\utymnwsa.3vd\restore.csproj] C:\Program Files\dotnet\sdk\6.0.200\NuGet.targets(130,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\Users\Anri_Kezeroti\AppData\Local\Temp\utymnwsa.3vd\restore.csproj]

The tool package could not be restored. Tool 'dotnet-sonarscanner' failed to install. This failure may have been caused by:

  • You are attempting to install a preview release and did not use the --version option to specify the version.
  • A package by this name was found, but it was not a .NET tool.
  • The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
  • You mistyped the name of the tool.

For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool

3 Answers

I had the same issue using v.5.7.2. There's a still open discussion on GitHub about that topic. It seems when calling dotnet install it will implcitely also call dotnet restore, which will use your Nuget.config. When there's a private feed that needs authentication within that file, dotnet install will fail instead of just using the next feed available. So we can add the official nuget-feed and ignore any others using the following:

dotnet tool install --global dotnet-sonarscanner --add-source 'https://api.nuget.org/v3/index.json' --ignore-failed-sources

This will still issue a warning because the private feed cannot be accessed. However it will process further and you can use the tool.

dotnet tool install --global dotnet-sonarscanner --version 5.5.3

Specifying version solved problem for me.

This problem is about authentication. Your nuget session may be expired or there might a problem about your credentials. In my case updating token in NuGet.Config solved this problem.

<add key="Username" value="your-username"/>
<add key="ClearTextPassword" value="your-new-token"/>
Related