7

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!

christok
  • 1,087
  • 2
  • 12
  • 29

1 Answers1

5

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.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 1
    Thanks, yes I tried this earlier and it does in fact download all packages, but I'd rather keep the vast majority of these in the global cache. I'm wondering if I can direct nuget only to download a single package to local packages folder. – christok Feb 20 '19 at 15:04
  • @christok, yes, check the update answer for some details. – Leo Liu Feb 21 '19 at 01:29
  • @christok, Just checking in to see if the information provided was helpful. Please let us know if you would like further assistance. – Leo Liu Feb 25 '19 at 02:09
  • This doesn't work for me. It downloads all packages to .\packages folder. I want to able to add specific package(s) from a solution's packages folder as the title of the question suggests. – Meeting Attender Oct 22 '19 at 19:36