Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to find nuget local source error occurred while restoring nuget packages the local source doesn't exist

I've been given a visual studio 2017 solution. When I open it fails as with the error:

Error occurred while restoring NuGet packages: The local source '\\network-location\' doesn't exist.

I can manually acquire a copy of these packages but I don’t know where this original path is configured and how I would go about changing it to the new location.

Any suggestions as to where I should look please?

like image 538
user9447717 Avatar asked Mar 23 '18 09:03

user9447717


People also ask

How do I force a NuGet package to restore?

Enable package restore by choosing Tools > Options > NuGet Package Manager. Under Package Restore options, select Allow NuGet to download missing packages. In Solution Explorer, right click the solution and select Restore NuGet Packages.

How do I fix NuGet recovery failed?

Quick solution for Visual Studio usersSelect the Tools > NuGet Package Manager > Package Manager Settings menu command. Set both options under Package Restore. Select OK. Build your project again.

Where can I find NuGet package source?

Find and install a packageIn Solution Explorer, right-click either References or a project and select Manage NuGet Packages.... The Browse tab displays packages by popularity from the currently selected source (see package sources). Search for a specific package using the search box on the upper left.

Where can I find the NuGet package sources?

Any suggestions as to where I should look please? The package sources can be found in the Visual Studio options ( Tools -> Options) under NuGet Package Manager -> Package Sources or directly by clicking on the according icon in the NuGet dialog (context menu of a solution/project -> Manage NuGet Packages... ):

How to fix ‘NuGet package provider cannot be found’ error in PowerShell?

To fix this error, First, we need to install the ‘Nuget’ package by following the above steps. Then run the below command which will De-register and register the repository again. register-packagesource : unable to find package providers (nuget). Now run the below line of code to install the Azure PowerShell module.

Why am I getting a NuGet installation error when trying to build?

This error occurs when you attempt to build a project that contains references to one or more NuGet packages, but those packages are not presently installed on the computer or in the project.

Why can’t I restore my NuGet package?

Microsoft.Bcl.Build and Microsoft.Bcl.Compression require custom target files, which do not work well with NuGet’s package restore feature. The easiest way to fix the package restore issues is by checking in any .targets files that are stored under the packages directory. What’s package restore?


2 Answers

The package sources can be found in the Visual Studio options (Tools -> Options) under NuGet Package Manager -> Package Sources or directly by clicking on the according icon in the NuGet dialog (context menu of a solution/project -> Manage NuGet Packages...):

enter image description here

Your local package source should then be listed in the following dialog:

enter image description here

The package source may, however, be solution or project specific and may therefore be specified in a NuGet.config file in the solution directory. Beginning with NuGet 3.4, Visual Studio looks in the project's directory or "or any folder up to the drive root", according to the NuGet.config reference. Up to NuGet 3.3, also subdirectories with the name .nuget where searched for NuGet.config files.

The file containing your local package source must be changed in order to restore the correct packages.

like image 95
Kristof U. Avatar answered Sep 28 '22 10:09

Kristof U.


Nothing of the proposed solutions above did it for me. And, honestly, I really don't like, what Microsoft is doing for some time now: each time there's another surprise when installing an update. :-(

Analysis:

Error occurred while restoring NuGet packages: The local source 'C:\Microsoft\Xamarin\NuGet' doesn't exist.

Obviously NuGet is trying to restore from C:\\Microsoft\\Xamarin\\NuGet for s solution that has nothing to do with Xamarin. The solution compiled many times before and even getting it back from GIT did not change anything. So, the problem is not my solution. It is something more global.

By the way: I DONT WANT TO USE THIS FOLDER, cause I don't use Xamarin!

I found the following reference in the *.csproj.nuget.dgspec.json files in any obj folder of my solution. All these json files pointed to this Xamarin folder:

"fallbackFolders": {
  "C:\\Microsoft\\Xamarin\\NuGet": {},  
  "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
  "https://api.nuget.org/v3/index.json": {}
},

Question: How does VS know about the fallbackFolders?

I did not find any hint in any of my Visual Studio / NuGet configuration settings, as proposed above. I deleted all objfolder but each time when trying to compile or restore my packages, the reference came back.

The SOLUTION for me was :

  • delete all objfolders in your solution (as mentioned above)

  • delete c:\Program Files (x86)\NuGet\Config\Xamarin.Offline.config

There you will find the following:

<fallbackPackageFolders>
    <add key="Xamarin Offline Packages" value="C:\Microsoft\Xamarin\NuGet\"/>
</fallbackPackageFolders>

This file was introduced on my machine one week ago, and I think it came with the latest VS update (16.2). I did not go away with the latest update (16.2.1) from today.

like image 24
Markus Schmidt Avatar answered Sep 28 '22 09:09

Markus Schmidt