SOLVED: dotnet tool update -g upgrade-assistant Unhandled exception:…

If trying to upgrade the upgrade-assistant, or installing it for that matter, you may get this ugly stack trace of errors. It’s not exactly straightforward, but there is an elusive solution if you pier through the error text.

The steps to resolve this are detailed in the next section.

I was trying to look to upgrade some legacy projects using the upgrade-assistant tool provided by the Visual Studio Marketplace or by downloading and installing it via the “dotnet tool” option.  I was more interested in using the dotnet CLI versus the GUI marketplace option.  
So I asked Chat GPT about the intricacies between dotnet and Visual Studio, already familiar with using “dotnet run” and “dotnet build” for Core projects.  It explained the following:

Visual Studio 2022 internally uses dotnet.exe to perform various tasks related to .NET development. When you create a new .NET project in Visual Studio, behind the scenes, Visual Studio uses dotnet.exe to scaffold the project structure and set up the necessary files. Similarly, when you build or run a .NET project within Visual Studio, it invokes dotnet.exe to perform the compilation, execution, and other necessary tasks.

So then it dawned on me that looking at the error stack in the error message, it is looking for something with NuGet and tells me what the package source ID is, namely, “upgrade-assistant”.  Let’s take a look at the part of the error message that gives us some clues on how to solve it, notwithstanding the actual link giving us more details.

Unhandled exception: Microsoft.DotNet.Cli.NuGetPackageDownloader.NuGetPackageInstallerException:   Package Source Mapping is enabled, but no source found under the specified package ID: upgrade-assistant. See the documentation for Package Source Mapping at https://aka.ms/nuget-package-source-mapping for more details.

Ah, package source mapping, that is in Visual Studio’s Tools -> Options page under Nuget Package Manager.  When looking in there, I went to the Package Source Mapping page, which is exactly what is specified in the error message above.  

Let’s check out this Add button.  Based on the error output, it is saying that the package ID named “update-assistant” is missing from the package manager.  I’ll add it as shown.

Now we see it in the list.  

Now the test, let’s re-run our upgrade command and see if this fixed it.

Yes!  We are in business.  

So, there is some new news here about how Visual Studio consumes packages.  Package Source Mapping is part of Nuget 6.0 and starting with Visual Studio 17.5 you can now use this process of adding or removing package source mappings with this Visual Studio Dialog box I’ve shown above.

For further reading and reference, you can check out the following links: