Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install the Nuget provider for PowerShell on a offline machine?

I am trying to install NuGet on an offline work machine running Windows Server 2016. Files can be uploaded to this machine via NAS. All online machines have restricted admin rights while the offline machine has full admin rights. I have found installation guides for offline machines, but they all assume that the online machine has admin rights.

How do I install the Nuget provider for PowerShell on a unconnected machine so I can install a nuget package from the PS command line? [Stack Exchange]

How to get PowerShellGet working with no Internet access [Intrepid Integration]

Bootstrap the NuGet provider and NuGet.exe [Microsoft]

These references recommend that NuGet is installed on an online machine (requires admin rights) then the installed dll is copied to the offline machine. Here's what I've tried so far:

  1. Tried to download NuGet on the offline machine to see where it downloads the files. It searches: https://onegetcdn.azureedge.net/providers/providers.masterList.feed.swidtag
  2. Followed the links in the URL and downloaded PackageManagement.NuGetProvider-2.8.5.208.dll
  3. On a personal computer (with admin rights) I downloaded NuGet the normal way and got the dll PackageManagement.NuGetProvider.dll installed in C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208\
  4. I checked the hash of both dll's and they matched.
  5. On the offline computer I created a C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208 folder and placed the dll from step 2 into this folder.
  6. I launched PowerShell as an admin and saw that NuGet 2.8.5.208 was installed but has no DynamicOptions. Any attempt to install nupkg packages failed. Here's what the output of Get-PackageProvider looks like:
PS C:\Windows\system32> Get-PackageProvider -ListAvailable
Name                     Version          DynamicOptions
----                     -------          --------------
msi                      3.0.0.0          AdditionalArguments
msu                      3.0.0.0
nuget                    2.8.5.208
PowerShellGet            1.0.0.1          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, ...
Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent

Notice that there are no DynamicOptions for NuGet. It clearly didn't install properly. I repeated this process for version 2.8.5.208 and 2.8.5.205 (both failed). I suspect there's an issue with the metadata of the dll I copied to the offline machine.

How can I get NuGet to install properly on my offline machine without admin rights on the online machines?

like image 494
Joe Avatar asked Oct 12 '19 01:10

Joe


People also ask

How do I install the NuGet provider for PowerShell?

Restart PowerShell to auto-load the package provider. Alternatively, run Get-PackageProvider -ListAvailable to list all the package providers available on the computer. Then use Import-PackageProvider -Name NuGet -RequiredVersion 2.8. 5.201 to import the provider to the current Windows PowerShell session.

How do I install PowerShell modules without Internet?

The first step for installing a powershell module on an offline computer is to download it with a computer that is connected to the internet. In the Start menu search for the Windows Powershell application and open it. On the command line type Save-Module -Name ModuleName -Path “FilePath” and Enter to run the command.


1 Answers

Download-Copy-Past solution

Run on your offline or online Windows machine
Install-PackageProvider -Name NuGet

If you receive the following error

Install-PackageProvider : Administrator rights are required to install packages in 'C:\Program Files\PackageManagement\ProviderAssemblies'.
  Log on to the computer with an account that has Administrator rights, and then try again,
  or install in 'C:\Users\\AppData\Local\PackageManagement\ProviderAssemblies' by adding "-Scope CurrentUser" to your command. You can also try running the Windows PowerShell session with elevated rights (Run as Administrator).
At line:1 char:1
+ Install-PackageProvider -Name NuGet

then run it with -Scope CurrentUser
Install-PackageProvider -Name NuGet -Scope CurrentUser

We need an URL from received error

WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''.
WARNING: Unable to download the list of available providers. Check your internet connection.
Install-PackageProvider : No match was found for the specified search criteria for the provider 'NuGet'. The package provider requires 'PackageManagement' and 'Provider' tags. Please check if the specified package has the tags.

Currently this will be https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409

So, go to an online machine and open this URL in a browser.
You'll receive the following XML

<?xml version="1.0" encoding="utf-8"?>
<SoftwareIdentity xmlns="http://standards.iso.org/iso/19770/-2/2015/schema.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:discovery="http://packagemanagement.org/discovery" patch="false" media="(OS:windows)" name="OneGet.Providers" tagVersion="1" uniqueId="OneGet.Providers.1" version="1.15.194.0" versionScheme="multipartnumeric">

    <!--
        This swidtag is a Discovery Feed that has pointers to the SWIDTAGs for
        the providers that the bootstrapper can download.
    -->

    <Link href="https://onegetcdn.azureedge.net/providers/nuget-2.8.5.208.package.swidtag" type="application/swid-tag+xml" rel="package" discovery:name="nuget" discovery:latest="true" discovery:version="2.8.5.208" media="(OS:windows)" />

    <Link href="https://onegetcdn.azureedge.net/providers/psl-1.0.0.210.package.swidtag" type="application/swid-tag+xml" rel="package" discovery:name="psl" discovery:latest="true" discovery:version="1.0.0.210" media="(OS:windows)" />

    <Link href="https://onegetcdn.azureedge.net/providers/ChocolateyPrototype-2.8.5.130.package.swidtag" type="application/swid-tag+xml" rel="package" discovery:name="chocolatey" discovery:latest="true" discovery:version="2.8.5.130" media="(OS:windows)" />

    <Link href="https://onegetcdn.azureedge.net/providers/nugetv2.feed.swidtag" type="application/swid-tag+xml" rel="feed" discovery:name="nuget" media="(OS:windows)" />

    <Link href="https://onegetcdn.azureedge.net/providers/psl.feed.swidtag" type="application/swid-tag+xml" rel="feed" discovery:name="nuget" media="(OS:windows)" />

    <Link href="https://onegetcdn.azureedge.net/providers/chocolateyprototype.feed.swidtag" type="application/swid-tag+xml" rel="feed" discovery:name="chocolatey" media="(OS:windows)" />
</SoftwareIdentity>

Copy the URL of the following form https://onegetcdn.azureedge.net/providers/nuget-X.X.X.XXX.package.swidtag
Currently it is https://onegetcdn.azureedge.net/providers/nuget-2.8.5.208.package.swidtag

Open this URL in a browser and you'll receive the following XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SoftwareIdentity xmlns="http://standards.iso.org/iso/19770/-2/2015/schema.xsd" xmlns:discovery="http://packagemanagement.org/discovery" xmlns:sha512="http://www.w3.org/2001/04/xmlenc#sha512" name="nuget" versionScheme="multipartnumeric" media="(windows)" tagVersion="1" version="2.8.5.208" uniqueId="nuget.2.8.5.208">

    <Meta providerName="nuget" providerVersion="2.8.5.208" summary="NuGet provider for the OneGet meta-package manager" />

    <Link href="https://onegetcdn.azureedge.net/providers/Microsoft.PackageManagement.NuGetProvider-2.8.5.208.dll" type="application/octet-stream" rel="installationmedia" discovery:targetFilename="Microsoft.PackageManagement.NuGetProvider.dll" discovery:type="assembly" media="(OS:windows)" />
</SoftwareIdentity>

You need an URL from the only href attribute.
This URL allows you to download the current .dll file of the current NuGet Provider for PowerShell. Currently it is https://onegetcdn.azureedge.net/providers/Microsoft.PackageManagement.NuGetProvider-2.8.5.208.dll

After downloading, navigate to this .dll file and unlock it (or use Unblock-File cmdlet)
Unlocking NuGetProvider dll file

Copy this file to C:\Program Files\PackageManagement\ProviderAssemblies on your offline machine.

Additional info

like image 127
it3xl Avatar answered Sep 29 '22 23:09

it3xl