Skip to content

dotnet tool install -g --add-source exception when private nuget packageSource (myget) exists #16215

Open
@copernicus365

Description

It's possible to install a .NET global CLI type tool as explained in this tutorial. While installation can be done via a public nuget package, one can also use the --add-source property to install directly from a .nupkg file (as the above tutorial demos). The problem is I had exceptions that in the end I discovered were due to having an extra private nuget packageSource registered on my system, which caused the installation to fail. Simply removing the extra source temporarily fixed the problem, but then adding it back, any subsequent attempts to install a global tool require the same workaround.

Example: If I have a .nupkg named microsoft.botsay (to use the above tutorial example, thus full file name being: microsoft.botsay.1.0.0.nupkg) located within C:\Tools\Botsay, the following should work:

dotnet tool install -g --add-source C:\Tools\Botsay microsoft.botsay

But I get this exception:

C:\Program Files\dotnet\sdk\5.0.103\NuGet.targets(131,5): error : Unable to load the service index for source https://www.myget.org/F/<some-company>/api/v3/index.json. [C:\Users<user>\AppData\Local\Temp\aqoqbaoa.yc5\restore.csproj]
C:\Program Files\dotnet\sdk\5.0.103\NuGet.targets(131,5): error : Response status code does not indicate success: 401 (Unauthorized).
The tool package could not be restored.
Tool 'microsoft.botsay' 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

As you can see there is a 401 Unauthorized exception when trying to read that myget feed, which clearly the only reason the system knows about it is because it's registered on one's system as a nuget package sourced.

One can navigate to their package manager settings via %appdata%/nuget where a NuGet.Config file exists, which is also what gets set by one's Visual Studio->Options->NuGet Package Manager->Package Sources form. In my case I had in addition to the normal nuget package source, a private myget source, listed last, by the same url as listed in the exception. One needs credentials to view that url in a browser etc. SIMPLY COMMENTING OUT that packageSource allows the above install command to succeed. One moment later and you can re-add the myget source, BUT: This would be a really bad experience if you need to have a team, etc, follow this workaround just to install this, as many other devs might easily have a private packageSource feed in their system as well.

My guess is that this tool reads all nuget sources listed as <packageSources> (reading the public nuget one first obviously) to see if there are any conflicts with the tool being installed. But then when it hits a private feed, which it is not authorized to open, the process fails and there is an exception, which terminates the install, even though otherwise that myget package source works fine in VStudio and on my system. It should just ignore that private (in this case myget) index.json file when it can't be read. That would fix this problem.

Cheers

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions