34

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?

10 Answers 10

55

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.

1
  • Thanks a lot! It helps me. I just did a folder cleanup and delete old projects where exists Source path for an old Nuget source. After deletion of unused nuget source the error has gone.
    – smily
    Commented Apr 5, 2021 at 18:57
27

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.

3
  • 1
    I found your answer only after having scanned all my disk searching for "c:\microsoft"... :-) All these nuget stuff is going crazier every day. I never allowed anything to create a "c:\microsoft" directory! Commented Sep 16, 2019 at 10:33
  • I had exactly the same problem with service fabric being referenced in a project where I was not using Service Fabric. Navigating to "c:\Program Files (x86)\NuGet\Config\" and deleting the service fabric file solved it for me. Commented Nov 6, 2019 at 8:00
  • Good find! FYI, I didn't need to delete obj folders. I just renamed Xamarin.Offline.config, appending a .txt extension (in case I need to restore it), and reloaded my solution; the .csproj.nuget.dgspec.json was regenerated without the C:\Microsoft folder. Yay! Commented Jan 9, 2020 at 17:32
24

You will encounter the same issue in Visual Studio 2019. I have the same issue, I thought it was a conflict on Visual Studio 2017 but it wasn't.

The fix is you have to remove the source that is causing the issue.

You can remove it via Tools -> NuGet Package Manager -> Package Manager Settings

1
  • 7
    Specifically, in my case, NuGet was looking for packages from the project itself, couldn't find them (correct, there are none), but wouldn't then try the default NuGet server. The fix was to uncheck the local project as a package source. Then NuGet happily retrieved the packages from nuget.org. Commented Jul 26, 2019 at 18:01
18

In my case i have getting this error: Error occurred while restoring NuGet packages: The local source 'C:\Microsoft\Xamarin\NuGet' doesn't exist.

I have accidentally deleted 'C:\Microsoft\Xamarin\' folder. After this VS2019 was not able to restore packages. I just manually created 'C:\Microsoft\Xamarin\NuGet' folder. Restarted VS, cleaned solution and everything goes well after this.

2
  • 1
    I had deleted that folder in order to make space. And it ended up breaking ASP.NET Core builds. Recreating C:\Microsoft\Xamarin\NuGet did the trick, no restart required. Commented May 21, 2020 at 13:29
  • This also worked for me. Created folder C:\Microsoft\Xamarin\NuGet Restarted Visual Studio
    – Dymond
    Commented Oct 5, 2021 at 10:17
13

All answers are relevant however they are not complete, wasted 30 mins on this.

Below worked fine:

1 . Clear cache & remove issue folders:

Tools > NuGet Package Manager > Package Manager Settings
      > NuGet Package Manager > General > Clear All NuGet Cache(s)

Tools > NuGet Package Manager > Package Manager Settings
      > NuGet Package Manager > Package Sources
                   > Available package sources
                   >   {uncheck the folder that is giving error}
                   >   OK

2 . Restore NuGet Packages on VS Solution

Right-click  on  Visual studio solution (not project)
      > Restore NuGet Packages

3 . Build & run project

Hope that helps.

6

I had this error in different situation. I checked contents of Nuget.config in my solution folder and under <packageSources> node it had an entry pointing to ./nuget. This folder didn't exist in the solution directory, so I just created an empty folder with this name and the solution compiled without any problems.

1

but I don’t know where this original path is configured and how I would go about changing it to the new location.

To resolve this error, please search the file NuGet.config in the given solution, then edit it with notepad, you will find following setting in that file:

  <packageSources>
    <add key="LocalServerName" value="\\network-location\" />
  </packageSources>

You could change the value to the new location.

1

In My case the only way to solve it was to clean up all the NuGet cache(s). You can find it at Tools -> NuGet Package Manager -> General

Clear All NuGet Cache(s) print

0

Same situation:

Error occurred while restoring NuGet packages: The local source 'C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages' doesn't exist.

My solution is re-creating the folder.

1
  • So same error and same solution as in existing answers. What exactly is then the additional insight which you contribute? Though you phrase "my solution" your post gives an impression of being a "Thanks Laimonas, thanks Episodex." for stackoverflow.com/a/59887427/7733418 and stackoverflow.com/a/57971770/7733418 Please kepp in mind that instead of posting "Thanks" as answers you are supposed to wait for your voting privilege and use it on existing answer posts.
    – Yunnosch
    Commented Aug 8, 2023 at 22:06
0

I had this issue when restoring packages for a Visual Studio .SLN from the command line.

It turns out that specifying the source on the command line with the -source option was causing the NU1301 error for the individual .csproj in the solution.

It started working when I stopped trying to explicitly specify the source.

Not the answer you're looking for? Browse other questions tagged or ask your own question.