1

I want to install OPCFoundation.NetStandard.Opc.Ua version 1.4.355.26 (and all of its dependencies) to an offline machine. My online and offline machines are running Visual Studio 2019 16.1.3.

When I install OPCFoundation.NetStandard.Opc.Ua version 1.4.355.26 using the NuGet Package Manager, it installs many dependencies, including Libuv.1.10.0. See screenshot:

NuGet Package Manager resolves Libuv.1.10.0

When I download the same package for offline installation, nuget.exe fetches Libuv.1.9.2. See screenshot:

nuget.exe resolves Libuv.1.9.2

C:\Users\cstankevitz\Downloads>nuget.exe install OPCFoundation.NetStandard.Opc.Ua
Feeds used:
  https://api.nuget.org/v3/index.json
  C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

Installing package 'OPCFoundation.NetStandard.Opc.Ua' to 'C:\Users\cstankevitz\Downloads'.
  GET https://api.nuget.org/v3/registration3-gz-semver2/opcfoundation.netstandard.opc.ua/index.json
  OK https://api.nuget.org/v3/registration3-gz-semver2/opcfoundation.netstandard.opc.ua/index.json 558ms


Attempting to gather dependency information for package 'OPCFoundation.NetStandard.Opc.Ua.1.4.355.26' with respect to project 'C:\Users\cstankevitz\Downloads', targeting 'Any,Version=v0.0'
Gathering dependency information took 16.89 sec
Attempting to resolve dependencies for package 'OPCFoundation.NetStandard.Opc.Ua.1.4.355.26' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'OPCFoundation.NetStandard.Opc.Ua.1.4.355.26'
Resolved actions to install package 'OPCFoundation.NetStandard.Opc.Ua.1.4.355.26'
Retrieving package 'Libuv 1.9.2' from 'nuget.org'.
...

Of course, when I bring the downloaded packages to my offline machine and install them using Visual Studio 2019 NuGet Package Manager, the install fails because the Libuv.1.10.0 is not available.

How can I get nuget.exe (or any other tool) to download the correct packages needed by NuGet Package Manager for offline installation?

CSDev
  • 3,177
  • 6
  • 19
  • 37

2 Answers2

2

Here is how I installed the correct dependencies to my offline system:

On the online system

  1. Fetch the source of https://github.com/StuffOfInterest/NuGetDependencyDownloader
  2. Edit PackageTools.cs and modify the function GetRangedPackageVersion so that it contains the code below. This is needed to fix a "bug" in which older packages are not downloaded when newer packages are available -- but the older packages will be needed in Step 9 below.
  3. Compile and run NuGetDependencyDownloader to download the package and its dependencies
  4. Copy the packages to an external drive

On the offline system

  1. Copy the packages to your offline system (c:\Work\2019-07018 Nuget Offline\ in my example)
  2. Edit options for Nuget Package Manager | Package Sources. Add a source that points to the directory used in step 5. Specify Local Package Source Screenshot
  3. Run Nuget Package Manager.
  4. Specify the Package source that you created in step 6. Specify package source screenshot
  5. Install your package
  6. Notice that it appears to install but nothing is actually happening. It is trying to contact something online (which will fail after a long timeout). This is repeated for every dependency. Speed up the failure by disconnecting all of your interfaces (unplug cables, etc).
    private IPackage GetRangedPackageVersion(IQueryable<IPackage> packages, IVersionSpec versionSpec)
    {
      packages = packages.Where(o => o.Version == versionSpec.MinVersion);

      IPackage package = packages
          .OrderByDescending(o => o.Version)
          .FirstOrDefault();

      return package;
    }
0

If you look at the output of the Preview Changes dialog in VS, all the Microsoft.AspNetCore packages are version 2.0.1, whereas running nuget.exe, it got versions 1.1.x. If you look at OPCFoundation.NetStandard.Opc.Ua on nuget.org and expand the dependencies, you see it has dependencies on the 1.1 packages for net46 and netstandard2.0, but 2.0 dependencies for netstandard2.0.

From this I can deduce that your project is using netcoreapp2.0, netstandard2.0, or above, whereas nuget.exe is probably using some .NET Framework for dependencies.

As for ways to get the same packages that your project actually uses, I've answered this question several times in the past and I usually link to the first time I answered it

zivkan
  • 12,793
  • 2
  • 34
  • 51