Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force download of specific nuget package to local packages folder

I have a .NET Core Visual Studio 2017 solution that references Json.Net 12.0.1. Everything works great in my dev environment. When I run dotnet restore, Json.Net is downloaded to Newtonsoft.Json.12.0.1 in the solutions packages folder.

However, when I run restore on my build server the solution wants to pick up a version of Json.Net from the nuget global cache.

I can force download of all packages to a local packages folder, but this ends up using a different naming convention (Newtonsoft.Json/12.0.1), and of course re-downloads all that stuff that exists in globals anyway. So it just creates a lot of overhead and still doesn't work.

I suppose I could work some hocus pocus in my .csproj files in oder to provide a different hint path for Json.Net but this seems overly complicated.

Is there a way to force Nuget to download Json.net (or any package) to a specific folder in local packages, or otherwise resolve this issue using CLI tools?

Again, this is .NET Core so there is no packages.config.

Thanks!

like image 859
christok Avatar asked Feb 19 '19 15:02

christok


1 Answers

Is there a way to force Nuget to download Json.net (or any package) to a specific folder in local packages, or otherwise resolve this issue using CLI tools?

Yes, you can place a NuGet.Config file next to the solution with the following content:

<?xml version="1.0" encoding="utf-8"?>
  <configuration>
    <config>
      <add key="globalPackagesFolder" value=".\packages"/>
    </config>
</configuration>

Then restart the Visual Studio, and re-open the solution and right click on the solution, select Restore NuGet Packages. All the packages are stored in the project repository.

I'm wondering if I can direct nuget only to download a single package to local packages folder.

Yes, you can download the nuget package with following command line:

nuget.exe install YourPackageName -source "https://api.nuget.org/v3/index.json" -OutputDirectory "D:\Test"

Hope this helps.

like image 197
Leo Liu-MSFT Avatar answered Oct 10 '22 15:10

Leo Liu-MSFT