Updating PackageManagement Module in PowerShell Core - Assembly Name Conflicts #170
Description
I have a little script that I'm working on that attempts to update the PackageManagement and PowerShellGet Modules in PowerShell Core if they're not the latest. It seems like I'm getting a race condition in PowerShell Core beta.6 and 7 when I attempt to update the PackageManagement Module.
Here's a Git Gist with both the script (~100 lines) and the resulting errors I get on PowerShell Core beta.6 and 7 (any OS):
https://gist.github.com/pldmgg/b8db54742d511bd7d8d5742d539ebbe1
The results of my testing have shown that:
-
It works fine on Windows PowerShell 5.1
-
It throws errors as seen in the above Gist in PowerShell Core beta.6 and 7 on any OS.
-
After the errors are thrown, using 'Get-Module' shows that the latest version of the PackageManagement Module is loaded, but there aren't any ExportedCommands
-
If I start a new PowerShell Core Session after experiencing the above errors and try the script again, everything works fine
So, the errors are pretty clear that there's a conflict with assembly names that are currently loaded / trying to be loaded, and I understand that the reason that starting a new PowerShell Core Session works is because that's the only way to unload previously loaded assemblies, but maybe there's a way to have PackageManagement.psm1 check to see if certain needed assemblies are already loaded before trying to load them again in PowerShell Core?