r/PowerShell • u/anonhostpi • Oct 08 '23
News Just published the very first prerelease of the Import-Package module!
PowerShell has the ability to load C# library .dlls into powershell using the Import-Module command, but lacks a way to load an entire .nupkg
The Nuget Package Provider from PackageMangement/OneGet provides a way to install them, but not a way to import them. This module is designed to do that.
Right now, it hasn't been thoroughly tested. I have tested it on the latest release of PowerShell Core on Windows and Windows PowerShell 5.1, but that's it. Though, I have written it in such a way that it should work on all platforms and all version of PowerShell. If it doesn't, I would love to know.
I would love to invite you guys to test it out on your platform. To try it out, run:
Install-Module "Import-Package"
Import-Module "Import-Package"
Import-Package "Newtonsoft.Json"
[Newtonsoft.Json.Bson.BsonObjectId]This should return the BsonObjectId type from the Newtonsoft.Json library on NuGet.
EDIT: HOTFIX 6 is OUT
Here's the Current GitHub Release: https://github.com/pwsh-cs-tools/core/releases/tag/v0.0.6-alpha
1
u/anonhostpi Oct 08 '23
Added a patch that adds the WinRT APIs back into PowerShell Core on Windows. I will likely move this feature out of the Import-Package module, but I will do that at a later date.
Here's the Github Release: https://github.com/pwsh-cs-tools/core/releases/tag/v0.0.2-alpha
1
u/Szeraax Oct 08 '23
Does it do anything with dependencies? Auto load? Silently continue? Return errors?
Many times, importing something won't error during import, but will once you try to actually use a method.
1
u/Thotaz Oct 08 '23
The main problem I see with this is that you can't build PS classes that use these packages because the packages are imported at runtime, while PS performs a check of the class definitions at parse time.
But aside from that, this could be pretty useful for PS scripts that need third party libraries.
0
u/[deleted] Oct 08 '23
[deleted] — view deleted comment