question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
wli3commented, Mar 5, 2021

use --ignore-failed-sources option will ignore failed feeds

0reactions
copernicus365commented, Mar 16, 2021

@wli3 interesting! While I personally think this should be the default behavior, I’m glad to know there is this option, will try to test it soon

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to install dotnet tool from private nuget feed
I have a dotnet tool that is published as a Nuget package to a private feed. From a YAML pipeline I would like...
Read more >
how to resolve "Unable to find package" nuget error
Step 03. Install the nuget.org as package source and then 'Clear All Nuget Cache(s)' and then restore the packages. The error will go...
Read more >
dotnet tool install command - .NET CLI
The dotnet tool install command installs the specified .NET tool on your machine.
Read more >
How to publish NuGet packages
See detailed instructions about how to publish a NuGet package and manage package ownership on nuget.org.
Read more >
Fixing NuGet error: Unable to load the service index for source
Solution 1. Use a NuGet config file. ... To work around this, I am creating a new nuget.config file and populating it with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found