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

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?

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:
Close VS
(Just in case) make a backup copy of the .sln (solution file)
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}"
Amend the second parameter and save:
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "http://www.devsite.com", "DevWebsiteFolderName", "{A8837508-9BC1-482A-86EF-4B3156CAFDBE}"
Open your solution.
Use NuGet as you wish :-)
Optional:
Close VS
Reverse your .sln change.
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

This was driving me nuts... I spent hours trying to install the Authorize.net nuget package in VS2017 and it kept throwing the same error.
I finally opened my project up in VS2015 and installed it without any issues.
Hope this helps.
Jason

Given that we haven't gotten any help from Microsoft on this, we've adopted the convention of doing something like what Barry Kaye suggested, but for the second parameter, just replacing it with a single period "."

This issue appears to be fixed in 15.6.0. Try upgrading to that version, if you can.

I encountered the same problem and I solve it this way:
Right-click on the project -> Properties -> Debug -> App URL
(The app URL was not the correct one)

Related

nuget dll is used by another process

I have the error from below and I'm quite out of ideas how to solve it. Tried the following until now:
Clean bin/obj/packages/packages cache
Remove manually from csproj and packages files the package and add it afterwards..still error
Update Visual Studio 2017
Reinstall Visual Studio 2017
Trace which processes are using a file with name that contains Newtonsoft
Copy the solution from another laptop where the builds works just fine
Yet, after all from above, I still get:
Error NuGet Package restore failed for project DriversApp.Android: Unable to find version '10.0.3' of package 'Newtonsoft.Json'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'Newtonsoft.Json.10.0.3' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
https://api.nuget.org/v3/index.json: Error downloading 'Newtonsoft.Json.10.0.3' from 'https://api.nuget.org/v3-flatcontainer/newtonsoft.json/10.0.3/newtonsoft.json.10.0.3.nupkg'.
The process cannot access the file 'C:\Users\user\.nuget\packages\newtonsoft.json\10.0.3\lib\netstandard1.0\Newtonsoft.Json.dll' because it is being used by another process.
. Please see Error List window for detailed warnings and errors.
How to get this solved? I got really stuck on this one...
After a lot of investigation and ideas, I've solved this by uninstalling the antivirus solution as the rules added by me within my laptop were overrode by the company server policies.
As a conclusion, first check your antivirus solution, and if you are within a controlled environment, make sure your rules are not overrode by company server policies.
Thank you, #Leo Liu-MSFT for the assistance.
nuget dll is used by another process
You can try to use following troubleshooting to resolve this issue.
In Windows Explorer go to the folder where the NuGet packages are installed C:\Users\user\.nuget\packages, deleted the Newtonsoft.Json folders.
May it has something to do with the same package being referenced in multiple projects within the same solution, adding "-DisableParallelProcessing" to the nuget restore command, the final command would look like:
nuget restore "%WORKSPACE%\Solutions\App\App.sln" -DisableParallelProcessing
Excluding NuGet package files from the anti-malware products, or try to disable the antivirus. The anti-malware/antivirus products briefly locking these files during the NuGet restore operations.
Clear all referenced libraries before build the project by right click to Solution in solution explorer after click to "Clean Solution".
Most probably I was faced when there is some other error in the project (ie: project reference error etc.)
try 0: Remove all bin & obj from all project.
Try 1: Restart PC
Try 2: close vs & %temp% delete all
Try 3: Disable antivirus for the moment
Try 4: Change Debug to Release and revert back
Try 5: Clear All nuget caches
If above nothing works then shut down your pc, sit back for moments, relax and then check back.
Run this command with admin rights (net session /delete). It worked for me.

Publish website without roslyn

I am trying to create web application using Visual Studio 2015 and .NET 4.5.1.
When I publish the website, visual studio create folder named roslyn.
I know it's used to compile code on the fly, but unfortunately my hosting provider doesn't allow me to execute the compiler on their server.
How to publish the website without roslyn like previous version of Visual Studio?
EDIT:
I got this error when trying to acces my website.
It seems IIS trying to execute roslyn\csc.exe but my user account doesn't have permission to do that. With previous version of Visual Studio, this error doesn't show up.
I've just faced the same problem. When you create a new web project, two nuget packages automatically added to your project. If you remove them, your problem should be solved. Package names are: "Microsoft.CodeDom.Providers.DotNetCompilerPlatform" and "Microsoft.Net.Compilers".
I had the same issue. Followed the steps from here. Basically:
Uninstall the package
Uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform <Your Web API project name>
In your publish profile settings, uncheck "Allow precompiled site to be updatable". You can find this under Settings > Precompile during publishing > configure
After searching the same issued I face, I just came here. I read the above answer which is right.
I give the answer, because of Here is the good article to explain :
Why the publish code have this exe as well as development environment ?
What is the benefit and how to remove?
This is also the very good article, about the history of this exe
After countless effort....and according to this website.
I find that you can use /p:UseWPP_CopyWebApplication=true /p:PipelineDependsOnBuild=false in MSBuild to transform web.config, this also include the roslyn compiler in the build. The output is same as what you get by publishing in Visual Studio into file system
There is an open bug on the roslyn repository about this issue.
In my case all I had to do was to downgrade the dll Microsoft.CodeDom.Providers.DotNetCompilerPlatform from version 1.0.6 to 1.0.5.
I have had the same issue in Sept2016 when I took over an existing ASP.NET program. I found that there were multiple versions of the two compiler packages mentioned by Kemal installed in different projects of the solution.
So firstly I updated to get them the same. VS doesn't tell you that updates are available in this scenario (or maybe I missed them ?)
I then had to restart VS2015 for the packages to clean up properly.

Visual Studio can't find Nuget packages from private Nuget Server

I am running NuGet.Server v2.8.60717.93, hosted on Azure. The server is running correctly, and I am able to see all the packages if I go to the following url:
https://***.azurewebsites.net/nuget/Packages
I am also able to publish new packages to the server using Nuget Package Explorer.
I added https://***.azurewebsites.net/nuget as a Package Source in Visual Studio. However it can't find any packages, it just says No items found.
To my understanding, Nuget will set /Packages as default package folder unless otherwise is specified. I even tried to set packagesPath to ~/Packages, still no luck.
What am I missing?
Also have this problem the RSS feed of package is showing in the browser if I navigate to https://***.azurewebsites.net/nuget/Packages but no items found in visual studio.

Visual Studio Online - Get Latest and NuGet

It's very possible that I'm missing something simple because I can't find others on the internet experiencing the same thing.
I'm a team that's new to the use of TFS and Visual Studio Online and we're encountering this problem:
(Using Visual Studio 2015 & 2013)
I used NuGet to add Microsoft.AspNet.WebApi.Cors to my newly created WebAPI project (ditto all other NuGet packages)
Did my work and checked in a building solution in to VSO
Co-worker did a Get Latest
His newly-retrieved project won't build and, when we expand the References, the assemblies are marked with a yellow warning icon, indicating that they're missing
We've tried (from the context of the failing project):
Update-Package
Update-Package -reinstall
Manually uninstalling and reinstalling the package in the NuGet UI
Manually adding the entire contents of the Packages directory in to TFS and doing a get latest on that directory as well
Wiping the solution out from his local file system and pulling it down clean
Copying the contents of my {Solution Directory}\Packages to a USB drive, walking it to my co-worker's computer, and copying it to his machine
Only item #6 worked but I'm CERTAIN that this cannot be the right answer.
I guarantee that this is worthy of a dope-slap but what might I be missing?
Thank you to jessehouwing for reminding me that this topic is still out here. He's exactly right on. We removed the Packages folder from source control and that resolved the problem completely.

Error when trying to enable NuGet Package Restore in new Solution

I am getting an error when trying to enable package restore in a new solution I just created. The error in VS2012 is:
NuGet Package Manager
An error occurred while configuring the solution to restore NuGet
packages on build
Unable to read package from path 'NuGet.Build.2.7.0.npkg'.
I tried opening the solution in VS2010 to work around the problem and I am also getting an error when trying to enable package restore, but the message is different:
NuGet Package Manager
An error occurred while configuring the solution to restore NuGet
packages on build
Archive file cannot be size 0.
I tried creating a new solution, but got the same result.
I then tried doing a repair on VS2012 update 3 and rebooting. Still getting the problem.
I also scanned the folder, project, and solution file for anything NuGet or .nupkg, but there is nothing there.
So how can I get this feature working again? The last time I used it was about a week ago, and I don't remember specifically what I changed since then. I uninstalled the VS Power Tools package that I installed about a week ago, but that didn't fix the problem either.
Update
I followed the "removal" instructions here and used a project I already have as a template to enable package restore manually. However, I am still looking for a better solution because this is a feature I use frequently.
I also tried uninstalling and reinstalling NuGet from visual studio, but I still get the same issue. If memory serves correctly, there was a recent NuGet update (is there a log for VS extension installation so I can check?).
I suspect that the NuGet.Build.2.7.0.npkg file is zero bytes due to a failed download. NuGet.Build.2.7.0.npkg is the NuGet package that Visual Studio downloads in order to enable package restore for your solution.
Take a look in your cache and see if this file is zero bytes. If so then delete the file or clearing the cache and try enabling package restore again. The cache is under your profile in a directory similar to:
C:\Users\YourUsername\AppData\Local\NuGet\Cache
You can also browse to the cache from inside Visual Studio by opening the Package Manager Settings, selecting General and clicking the Browse button.
All of the previous answers, plus this one: can you run .\nuget\nuget.exe update -self if this is a solution in which package restore was previously enabled?
check whether your nuget package manager is updated one or not.
Check this from Tools-> Extensions and Updates -> Updates
Update your Nuget Package Manager and then it will work

Resources