PowerShell / PowerShellGetv2

PowerShellGet is the Package Manager for PowerShell
https://www.PowerShellGallery.com
MIT License
432 stars 138 forks source link

Offline installation of modules from Save-Module does not work on PS <5.x #171

Open jakerobinson opened 7 years ago

jakerobinson commented 7 years ago

Save-Module downloads modules including a version folder in the path. Older versions of Powershell don't know how to import modules with a version in the folder path, and requires users to manually move around files to get the modules to work.

A user has provided details and a workaround here: http://www.powershellcrack.com/2017/09/installing-powercli-on-disconnected.html

See also: https://communities.vmware.com/thread/564258

Edit: Adding more info to save people time when they read this. :)

The problematic workflow is this:

A user has PS 5.x on their machine connected to the Internet, and PS <5.0 on their machine not connected to the Internet. They want to install modules from the gallery on their non-connected machine.

  1. Use Save-Module to get module from gallery. (Saved with version folders in path).
  2. ⛔️ Perform manual file copies to remove the version number in path
  3. Copy fixed modules over network to PS <5.0 (no Internet) machine
bmanikm commented 7 years ago

@jakerobinson Yes, the workaround is to use Save-Module on PS 4 or 3.

Option: -NoVersionFolder switch parameter can be added on Save-Module cmdlet to not create the version folder on PS 5 or newer. Thoughts?

jakerobinson commented 7 years ago

That sounds like a perfect solution. :)

jakerobinson commented 7 years ago

Also, how deep does this go? I am trying to find where that path gets added, and install-package from OneGet has the same behavior. I am guessing it is even deeper in the PackageProvider? What is actually putting that version into the path, and where do we want to remove it?

bmanikm commented 7 years ago

@jakerobinson https://github.com/PowerShell/PowerShellGet/blob/acee8cc49c4f8309776f30d1553a1b14f37fb09c/PowerShellGet/PSModule.psm1#L11099

brianbunke commented 6 years ago

Took a crack at this tonight and failed.

After module restructure, the offending lines are now:

https://github.com/PowerShell/PowerShellGet/blob/f0728e01a5f972b2afbde0fd3acfee498d36ed21/PowerShellGet/private/functions/Install-PackageUtility.ps1#L587

https://github.com/PowerShell/PowerShellGet/blob/f0728e01a5f972b2afbde0fd3acfee498d36ed21/PowerShellGet/private/functions/Install-PackageUtility.ps1#L848

As far as I can tell, the flow from Save-Module is something like:

Save-Module > PackageManagement\Save-Package > [unknown] > Download-Package > Install-PackageUtility

I'm not sure how to persist the -NoVersionFolder parameter flowing out of and back into this module.

Hopefully this info helps the next person make this happen.