Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuget package install error -- Invalid URI: The Authority/Host could not be parsed

I'm using NuGet within Visual Studio 2017 to try to install a package on an older Web Forms project, and it is failing with the following error:

Invalid URI: The Authority/Host could not be parsed

This only happens when trying to install the package on a website that is mapped in IIS (other types of projects work fine), so the project name is http://localhost..., etc., which is what I think it's having trouble parsing. It worked fine until just a few days ago and I'm not sure what caused it to change. Here is the full message I am receiving:

Resolved actions to install package 'Newtonsoft.Json.10.0.3'
Found package 'Newtonsoft.Json 10.0.3' in 'd:\packages'.
Package 'Newtonsoft.Json.10.0.3' already exists in folder 'd:\packages'
Install failed. Rolling back...
Package 'Newtonsoft.Json.10.0.3' does not exist in project 'http://localhost:89/'
Executing nuget actions took 71.95 ms
Failed to add reference to 'Newtonsoft.Json'.
     Invalid URI: The Authority/Host could not be parsed.

Another related clue is that when I open "Manage NuGet Pacakges..." on the website project, it is not showing anything as being installed, even though the packages.config file clearly exists in this project with several references defined.

My environment is as follows:

Visual Studio Professional 2107 Version 15.5.2, Microsoft.NET Framework Version 4.7.02556, NuGet Package Manager Version 4.5.0, and my NuGet repository is set to install in D:\packages

Does anyone have any advice on what setting I might be able to change to get this working again?

like image 216
adsilb Avatar asked Dec 16 '17 08:12

adsilb


1 Answers

NuGet does not appear to be working for local IIS Web Site projects in VS 15.5.1 to 15.5.5 (inclusive).

The workaround is:

  1. Close VS
  2. (Just in case) make a backup copy of the .sln (solution file)
  3. In a text editor open the .sln file and find the line:

Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "http://www.devsite.com", "http://www.devsite.com", "{A8837508-9BC1-482A-86EF-4B3156CAFDBE}"

  1. Amend the second parameter and save:

Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "http://www.devsite.com", "DevWebsiteFolderName", "{A8837508-9BC1-482A-86EF-4B3156CAFDBE}"

  1. Open your solution.
  2. Use NuGet as you wish :-)

Optional:

  1. Close VS
  2. Reverse your .sln change.
  3. Open VS

For credit and further reference:

NuGet fails for website projects hosted on local IIS

Nuget looking in wrong location for packages.config in web forms web site running on IIS

like image 185
Barry Kaye Avatar answered Nov 09 '22 23:11

Barry Kaye