Skip to content

Support for platform-specific binary dependencies? #138

Description

@markm77

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-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....

Activity

  1. markm77 commented on May 10, 2020

    @markm77
    Author

    FYI more info on my particular unwanted platform dependency in case of interest.... dotnet/efcore#9505 (comment) 😊

  2. JustinGrote commented on May 14, 2020

    @JustinGrote
    Contributor

    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.

  3. markm77 commented on May 14, 2020

    @markm77
    Author

    Thanks Justin Grote (@JustinGrote).

    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?

    Is this possible and is this what you mean?

  4. JustinGrote commented on May 14, 2020

    @JustinGrote
    Contributor

    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/

  5. markm77 commented on May 14, 2020

    @markm77
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions