Repository navigation
Support for platform-specific binary dependencies? #138
Description
Activity
FYI more info on my particular unwanted platform dependency in case of interest.... dotnet/efcore#9505 (comment) 😊
JustinGrote commented
on May 14, 2020 ContributorMore actionsMark Murphy (@markm77) this isn't really powershellget specific. A common technique is in your module .psm1 file to detect the platform (using $isWindows or $isLinux as one potential method) and load the appropriate assemblies/binaries for the platform, if you can't use Powershell Standard to create cross-platform assemblies.
Thanks Justin Grote (@JustinGrote).
Here's how I'm interpreting what you suggest. I could do a
dotnet publishfor each supported platform to generate the platform-specific DLL and dependencies in a platform-specific folder. Then I could publish all of these folders plus the .psm1 to PowerShell gallery and use the psm1 to point to the correct folder at run-time?Is this possible and is this what you mean?
JustinGrote commented
on May 14, 2020 ContributorMore actionsCorrect and use add-type to load the .dlls, and assign a variable to the commands you want to run if they are binary '.exe' files.
See pester for an example:
https://github.com/JustinGrote/Pester/blob/v5.0/src/Pester.Types.ps1Also these are good articles on the subject:
https://docs.microsoft.com/en-us/powershell/scripting/learn/writing-portable-modules?view=powershell-7
https://devblogs.microsoft.com/powershell/depending-on-the-right-powershell-nuget-package-in-your-net-project/Thanks for your links. Since I don't need to support pre-v7 PowerShell, looking at this indicates actually I just need to use correct subfolders for the DLL (and hopefully dependencies??). I will need to try this, hopefully this is all compatible with output of
dotnet buildanddotnet publishwith mulitple target frameworks. That would be nice.I have moved away from
add-typeand back toimport-moduledue to various issues (see here). Hopefully import-module respects the subfolder structure above (auto-selects correct subfolder) in PowerShell v7.Let me test all this which seems a perfectly reasonable way to support platform-specific binary dependencies in a single PowerShell gallery package with no help required from PowerShellGet. If it works, I'll close this.
- addedIssue-EnhancementNew feature or requestNew feature or request
on Sep 8, 2020
See e.g. https://stackoverflow.com/questions/51732417/how-can-i-publish-a-powershell-gallery-module-that-depends-on-a-platform-specifi.
I also have the same issue as e.g. on Windows need to generate my binary module using
dotnet publish -r win10-x64rather thandotnet publishto make it work locally (I believe the issue is to do with the SQLite driver for EF Core).This makes it a bit tricky to publish a cross-platform binary module via PowerShell Gallery....