You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support for platform-specific binary dependencies? #138
I also have the same issue as e.g. on Windows need to generate my binary module using dotnet publish -r win10-x64 rather than dotnet publish to 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....
Mark 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.
Here's how I'm interpreting what you suggest. I could do a dotnet publish for 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?
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 build and dotnet publish with mulitple target frameworks. That would be nice.
I have moved away from add-type and back to import-module due 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.
Activity
markm77 commentedon May 10, 2020
FYI more info on my particular unwanted platform dependency in case of interest.... dotnet/efcore#9505 (comment) 😊
JustinGrote commentedon May 14, 2020
Mark 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.
markm77 commentedon May 14, 2020
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 commentedon May 14, 2020
Correct 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.ps1
Also 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/
markm77 commentedon May 14, 2020
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.