Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to restore nuget packages in Visual Studio for Mac & dotnet core with slow (Bolivian) internet

I'm having problem restoring packages for a dotnet core 2.0 project here in Bolivia. Back home in The Netherlands I have no problems restoring the packages, but here it breaks.

I'm getting a lot of errors like:

Failed to download package 'System.Linq.4.1.0' from
'https://api.nuget.org/v3-flatcontainer/system.linq/4.1.0/system.linq.4.1.0.nupkg'.
An error occurred while sending the request
  Error: SecureChannelFailure (Unable to write data to the transport connection: Cannot access a disposed object.
  Object name: 'System.Net.Sockets.Socket'..)
  Unable to write data to the transport connection: Cannot access a disposed object.
  Object name: 'System.Net.Sockets.Socket'..
  Cannot access a disposed object.
  Object name: 'System.Net.Sockets.Socket'.
Unable to load package 'System.Linq'.

When I try to wget this file I'm getting between 400 KB/s and 3 MB/s.

I'm thinking it's nuget restoring the packages in parallel and that causes the Hostel internet to be fully used? I have tried it in different Hostels/Cafe's here, and I'm getting the same problems. When I Remote Desktop into my home server in the Netherlands and restore the packages for the same project it's all going well.

What are my options here? I tried googling this problem for a while, but I haven't found a solution yet.

Thanks!

Jorik

like image 795
Jorik Avatar asked Dec 23 '22 14:12

Jorik


2 Answers

I cannot help with the networking problem but you may be able to reduce the amount of NuGet packages that are being downloaded by Visual Studio for Mac as a possible workaround. This can be done for a .NET Core 2.0 project by using the NuGet fallback folder:

/usr/local/share/dotnet/sdk/NuGetFallbackFolder/

The fallback folder holds many NuGet packages that are used by .NET Core 2.0 by default. This folder should be created if you install the .NET Core SDK.

Using the above folder will prevent a lot of NuGet packages from being downloaded.

You can either add it directly as a NuGet package source or edit your ~/.config/NuGet/NuGet.Config file and add the fallback folder as follows:

Alternatively you could add an explicit fallback folder into your ~/.config/NuGet/NuGet.Config file:

<fallbackPackageFolders>
  <add key="DotNetCore2FallbackFolder" value="/usr/local/share/dotnet/sdk/NuGetFallbackFolder" />
</fallbackPackageFolders>

Visual Studio for Mac would need to be restarted. Also check that the folder exists.

Note that due to another bug Visual Studio for Mac will still download a few NuGet packages when restoring a .NET Core project.

like image 186
Matt Ward Avatar answered Apr 29 '23 02:04

Matt Ward


What are my options here? I tried googling this problem for a while, but I haven't found a solution yet.

Obviously, the reason for this error is the networking problem, however, just as Matt said, we could not give you much much help for the networking problem. I would like provide another workaround:

Since nuget restore the packages from local package cache by default and you can restore packages successfully in your home server in the Netherlands:

You can copy those packages from you home server and add them into local package cache C:\Users\username\.nuget\packagesto your machine in Bolivia.

Hope this helps.

like image 37
Leo Liu-MSFT Avatar answered Apr 29 '23 02:04

Leo Liu-MSFT