Description
SHILL DISCLAIMER: The reddit links are to my posts. Not trying to farm. I just don't know of anyone else who has already started work on this.
Background
A little known fact about PowerShell is that it too is also a CLR language just like C#. This means that .dll libraries written for C# can also be used in PowerShell.
IronPython currently takes advantage of this to make Python APIs available directly in PowerShell:
- README: https://github.com/IronLanguages/ironpython3?tab=readme-ov-file#Installation
- usage guide: https://www.reddit.com/r/PowerShell/comments/1luv01h/comment/n24bglu/?context=3
C# vs PowerShell and Applicability to Python.NET
One of the major differences between the 2 languages is how .nupkgs are treated. PowerShell expects them to be PowerShell modules and not bundled C# libraries. Natively, PowerShell doesn't know how to parse and handle .nupkgs pulled from NuGet. It's only designed to handle the ones provided by PowerShell Gallery.
This means that using the existing .nupkgs built for NuGet won't be usable out of the box. There are 2 options for implementing:
Utilize IronPython's Existing Solution (Recommended)
IronPython builds and ships a separate .zip archive to be used by ipy
and powershell
for easy embedding. You could just port this practice over the way it is. This method is also well-maintained
For more on how this method would be utilized, you can read about it here:
- setup and usage guide: https://www.reddit.com/r/PowerShell/comments/1luv01h/comment/n24bglu/?context=3
Implement a NuGet Package Parser in PowerShell (Not Recommended)
While this option is future proof and may come with other benefits, I don't recommend this option. It requires more work and more overhead. A strong argument could be made that this would be out of scope for this project.
I have done this before, but my solution is unmaintained. I also believe the most recent version is broken (older versions--older than version 0.4--reportedly work): https://github.com/pwsh-cs-tools/Import-Package
This uses NuGet's own C# libraries for parsing their own packages then uses that to break C# .nupkgs down into their relevant files for the target OS.
This is the other benefit. NuGet packages are currently designed to be digested at compile time. Developing this tool would not only allow them to be digested in PowerShell, but be digested at runtime in general, allowing C# developers to import .nupkgs as desired at runtime. Again, while nice, this is out of scope. So take that into consideration when deciding to add this to the stuff you want to maintain.
For more on how this method would be utilitized, you can read about it here:
- most relevant: https://www.reddit.com/r/PowerShell/comments/192uavr/turning_powershell_into_a_python_engine/
- how to develop solution: https://www.reddit.com/r/PowerShell/comments/171886q/nugetpackaging_in_powershell_a_dependency_for/
- another use case: https://www.reddit.com/r/PowerShell/comments/199i7nr/now_presenting_the_thanos_shauntlet/
- where
Import-Package
started: https://www.reddit.com/r/PowerShell/comments/172t0sj/just_published_the_very_first_prerelease_of_the/