Open glatzert opened 4 years ago
Can you run get-module powershellget -listavailable
and share that output?
PS> Get-Module PowerShellGet -ListAvailable
Directory: C:\Program Files\PowerShell\Modules
ModuleType Version PreRelease Name PSEdition ExportedCommands
---------- ------- ---------- ---- --------- ----------------
Script 2.0.1 PowerShellGet Desk {Find-Command, Find-DSCResource, Find-M…
Directory: C:\program files\powershell\7\Modules
ModuleType Version PreRelease Name PSEdition ExportedCommands
---------- ------- ---------- ---- --------- ----------------
Script 2.2.3 PowerShellGet Desk {Find-Command, Find-DSCResource, Find-M…
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version PreRelease Name PSEdition ExportedCommands
---------- ------- ---------- ---- --------- ----------------
Script 2.0.0 PowerShellGet Desk {Find-Command, Find-DSCResource, Find-M…
Script 1.0.0.1 PowerShellGet Desk {Install-Module, Find-Module, Save-Modu…
And $PSVersionTable
PS> $PSVersionTable
Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Out of interest I imported it manually:
PS> ipmo PowerShellGet -MinimumVersion "2.2.3"
and now am able to use it.
Might there be a Problem with your module-loading preference?
For further reference - I probably have lot's of versions, since I author an package and upload it to PSG. Thus I installed an upgrade of PackageManagement into 5.1 and also used it from 6.0 (using install or update as well, probably)
Thanks @glatzert, to be clear your issue is resolved if you import version 2.2.3 correct?
I can mitigate the issue by explicitly loading PackageManagement Version 2.2.3. So I'd not call it resolved, but I'm not the one deciding for your product.
I think I found the underlying problem for the issue.
I installed Powershell 6 some time ago and it created C:\Program Files\PowerShell\Modules
where PowerShellGet 2.0.1
has been placed by PS6.
If you install PowerShell 7, it'll place PowershellGet 2.2.3
in C:\program files\powershell\7\Modules
.
The $env:PSModulePath will be
C:\Users\MyUserPAth\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\powershell\7\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
Thus giving the PS7 Module directory apparently a lesser preference than the PS6 module directory. Also module loading seems to use the first match (as opposed to the highest version match) and use that.
My proposal to resolve the problem would be to adjust the installer, so it swaps the PS6 and PS7 module path, giving the PS7 module path a higher preference. This could also impact users moving from PS7 to PSvNext.
@glatzert I missed this comment, but thanks for this in depth investigation! I actually think the ordering of your module paths is correct... the 'c:\program files\powershell\7\Modules' path should contain the modules that come in-box with PowerShell 7 and the 'C:\Users\MyUserPAth\Documents\PowerShell\Modules' and 'C:\Program Files\PowerShell\Modules' should contain modules installed and scoped to either the current user or all users (respectively).
Are you able to reproduce your original issue again? If so, I'm curious if changing the modules path so that 'c:\program files\powershell\7\Modules' comes before all the other paths allows you to install without any errors? If it does, a potential workaround could be to then use Save-Module PowerShellGet -Path 'C:\Users\MyUserPAth\Documents\PowerShell\Modules' to install the latest version of PSGet into the current user scope module path and then revert $env:PSModulePath to its original ordering.
I can recreate the original issue, if I swap the paths. Module loading seems to prefer the latest version from each location, but stops looking in other locations if one matches (thus loading the older 2.0.1 from the path, which PS6 already used to insall it).
I swapped the pathes (7 before plain) and it loads fine for PS7, but then creates issues for PS5 (probably because, I messed up the PSModulePath a little bit), since it cannot load the version for PS7.
Long story short, you can "fix" it (on a given machine), by making sure, the generic location does not contain the module. But it's all a little bit messy.
You should be able to repro the issue by using Save-Module with version 2.0.1 to install it into the C:\...\PowerShell\Modules
path.
It was late, when I answered, so I did not fully digest PowerShell/7/Modules
being the out-of-the-box packages, so - yes - the order is correct.. Nevertheless, if you are upgrading and have a smaller version in your Powershell/Modules
directory, it'll get messy.
What solved it for me (for good now):
I'm running into the same issue and the workaround isn't working for me.
My PowerShell 5 stopped working after accidentally syncing my Documents folder to OneDrive (a whole different issue). I installed PS7 as a workaround and it's been fine until recently, and now I am unable to update or install modules.
The following error occurs when attempting the above workaround. NuGet does in fact show up when I run Get-PackageProvider -ListAvailable
Update-Module PowerShellGet
Import-PackageProvider: C:\Program Files (x86)\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7365
Line |
7365 | … $null = PackageManagement\Import-PackageProvider -Name $script:Nu …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| No match was found for the specified search criteria and provider name 'NuGet'. Try 'Get-PackageProvider
| -ListAvailable' to see if the provider exists on the system.
NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet
provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\...\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running
'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import the
NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"):
Install-PackageProvider: C:\Program Files (x86)\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7468
Line |
7468 | … $null = PackageManagement\Install-PackageProvider -Name $script:N …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Unhandled Exception - Message:'The type initializer for
| 'Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType' threw an exception.'
| Name:'TypeInitializationException' Stack Trace:' at
| Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.Create(Type tInterface, OrderedDictionary`2
| instanceMethods, List`2 delegateMethods, List`1 stubMethods, List`2 usedInstances) at
| Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.CreateProxy(Type tInterface, Object[]
| instances) at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast(Type
| tInterface, Object[] instances) at
| Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast[TInterface](Object[]
| instances) at
| Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterfaceExtensions.As[TInterface](Object
| instance) at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.get_PackageManagementHost() at
| Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.SelectProviders(String[] names) at
| Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_SelectedProviders() at
| Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider.get_SelectedProviders() at
| Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.<get_CachedSelectedProviders>b__23_0()
| at
| Microsoft.PackageManagement.Internal.Utility.Extensions.DictionaryExtensions.GetOrAdd[TKey,TValue](IDictionary`2 dictionary, TKey key, Func`1 valueFunction) at Microsoft.PackageManagement.Internal.Utility.Extensions.Singleton`1.GetOrAdd(Func`1 newInstance, Object primaryKey, Object[] keys) at Microsoft.PackageManagement.Internal.Utility.Extensions.SingletonExtensions.GetOrAdd[TResult](Object primaryKey, Func`1 newInstance, Object[] keys) at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_CachedSelectedProviders() at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.GenerateDynamicParameters() at Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.<AsyncRun>b__0()'
Import-PackageProvider: C:\Program Files (x86)\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7474
Line |
7474 | … $null = PackageManagement\Import-PackageProvider -Name $script:Nu …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| No match was found for the specified search criteria and provider name 'NuGet'. Try 'Get-PackageProvider
| -ListAvailable' to see if the provider exists on the system.
Get-PackageProvider: C:\Program Files (x86)\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7478
Line |
7478 | … tProvider = PackageManagement\Get-PackageProvider -Name $script:NuGet …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Unhandled Exception - Message:'The type initializer for
| 'Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType' threw an exception.'
| Name:'TypeInitializationException' Stack Trace:' at
| Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.Create(Type tInterface, OrderedDictionary`2
| instanceMethods, List`2 delegateMethods, List`1 stubMethods, List`2 usedInstances) at
| Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.CreateProxy(Type tInterface, Object[]
| instances) at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast(Type
| tInterface, Object[] instances) at
| Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast[TInterface](Object[]
| instances) at
| Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterfaceExtensions.As[TInterface](Object
| instance) at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.get_PackageManagementHost() at
| Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.SelectProviders(String name) at
| Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider.ProcessProvidersFilteredByName() at
| Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider.ProcessRecordAsync() at
| Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.<AsyncRun>b__0()'
Update-Module: NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed.
Thanks @CobyPear can you please run the following and share your output:
Get-Module -Name "PowerShellGet", "PackageManagement"
If your package management version is <1.4.7 can you run the command:
Install-Package -Name PackageManagement -MinimumVersion 1.4.7 -Force -Source PSGallery
If PowerShellGet version is less than 2.2.5:
Install-Module -Name PowerShellGet -RequiredVersion 2.2.5 -Force
Import-Module PowerShellGet
This will give us more information regarding your environment and the issue you are facing.
Thanks for the reply @StevenBucher98
Oddly enough, after running Install-Package -Name PackageManagement -MinimumVersion 1.4.7 -Force -Source PSGallery
with PowerShell 5, it worked perfectly. It's been a few days since I was messing with it, but maybe clearing out my PSModulesPath did the trick this time? The script I was trying to run now works.
I also set the TLS to 1.2 which seemed to solve the issues I was having on PS7.
god! it spent me 10 days!finally
so the reason is that,the modules that powershell using dont fit .I need add my current version's path into $PSModulePath ,and it must be the first one!
(This issue has been postet do OneGet as well, but PSGallery points here for PackageManagement, so I recreate a similar one here).
I tried moving to PS7 and got stuck with module installation via PowerShellGet:
This seems like a hen-and-egg problem for me, and I have tried multiple ways to solve it. Can you advise, what needs to do, to "reset" PowerShellGet into a working state? (Reinstalling PowerShell, did not resolve the issue).