Skip to content

Current module manifest schema is not adequate to properly support cross-platform modules #5541

Closed

Description

It is not going to be uncommon for module authors to want to provide slightly different functionality on different operating systems e.g. the module provides 30 commands, two of which only work on Windows PowerShell. Right now, there is no good way to declare "conditional" module exports in the manifest where the condition is the OS platform.

In fact, even PowerShellVersion is problematic if you design your module to load into both Windows PowerShell and PowerShell Core. Which PowerShell version does that refer to? Windows PowerShell? PowerShell Core? What if at some point, on PS Core I require 6.1.0? Does that mean my module can't load into Windows PowerShell 5.x anymore - probably. But I may not be providing that functionality when I'm loaded into Windows PowerShell (runtime decision) so Win PS 5.1 should be allowed when loading into Windows PowerShell.

AFAICT all of these field's values may be conditional upon the OS platform and/or the PowerShell platform (Win or Core)

  • PowerShellVersion
  • PowerShellHostName / Version
  • RequiredAssemblies
  • RequiredModules
  • ModuleList
  • NestedModules
  • FormatsToProcess
  • ScriptsToProcess
  • TypesToProcess
  • ClrVersion
  • DotNetFrameworkVersion
  • AliasesToExport although CompatiblePSEditions might mitigate this one
  • CmdletsToExport
  • FunctionsToExport
  • VariablesToExport
  • Tags

In order to make any changes backwards compatible with existing Windows PowerShell instance, we could put all the conditional declarations in PrivateData. This implies that fields not in PrivateData inherently apply to Windows PowerShell when module is loaded by Windows PowerShell. PowerShell Core could be modified to process the conditional fields in PrivateData. What might those look like? Maybe this?

    PrivateData = @{
        PSManifestEx = @{
            PowerShellVersion = "6.1.0" # fields at this level apply to all OS platforms for PS Core
            Linux = @{
                RequiredModules = @(...)
                CmdletsToExport = @(...)
            }
            MacOS = @{
                RequiredModules = @(...)
                CmdletsToExport = @(...)
            }
            Windows = @{ # this is for PowerShell Core on Windows
                RequiredModules = @(...)
                CmdletsToExport = @(...)
            }
        }

This doesn't take into account Nano server which I don't have enough experience with to take it into account. Anyway, this is just something to get the conversation started.

Long term, this approach seems less than ideal - burying so much important metadata under PrivateData.

Activity

  1. lzybkr commented on Nov 25, 2017

    @lzybkr
    Contributor

    I originally proposed allowing variables like $IsLinux in the module manifest so you could write:

    ExportedCmdlets = @(
        'Get-Thing'
        if ($IsLinux) { 'Get-LinuxThing' }
    )

    Untested, but I think all that is needed is to add to this list.

  2. mklement0 commented on Mar 8, 2018

    @mklement0
    Contributor

    A complementary aspect is how to restrict a module to an edition / a (set of) platform(s):

    • From what I can tell, setting CompatiblePSEditions to one edition isn't being enforced at module import time.

    • It seems that there is no key at all to limit support to a given (set of) platform(s).

    (Note that edition support and platform support are independent dimensions; conceivably, modules can run on both editions while requiring Windows as the platform.
    Conversely, though, limiting support to non-Windows platforms implies the Core edition.)

  3. fMichaleczek commented on Apr 17, 2019

    @fMichaleczek
    Contributor

    I would like to contribute and make a PR for this issue :

    Anything else ?

  4. vexx32 commented on Apr 17, 2019

    @vexx32
    Collaborator

    That sounds like a good start, go for it! 😄

  5. fMichaleczek commented on May 1, 2019

    @fMichaleczek
    Contributor

    I would like to add PSVersionTable too, someone against that ?
    Architecture is still a missing information in PSVersionTable but can be added later #8047

  6. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  7. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  8. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  9. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions