Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Problem

Historically the manifest's RequiredModules dependencies specification in PowerShell was overly optimistic wrt to semver and major version changes, i.e. Version translates to [x,) - so, basically from x onward, which is guaranteed to break at some point for all packages. RequiredVersion solves the problem, but obviously can only be applied to the packages you author.
We're seeing this issue most acutely with PowerCLI, which breaks even across minor revisions - installing 2 PowerCLI versions side-by-side is guaranteed to fail imports for older versions.

What I've tried

I've tried addressing it in user-space which kinda works, but apparently import does some things that cannot be replicated in user-space - I'm occasionally hitting hard to reproduce problems importing the ordered dependency graph. It looks like earlier in the import order module/command is not visible to the next module that depends on it, leading to either missing commandlet or "assembly already loaded" errors depending on w/ autoload is enabled. I must be missing something, but I don't see what.

Proposal

These days every package management comes with support for lockfiles, which I'm sure everyone could appreciate the importance of and it would be good to have that 1st class supported in PowerShell, at least for import.

How I imagine this working:
-LockFile <file name> and/or -LockMap <Hashmap>

CDR mentioned above implements semantics of the proposed module mapping.

RFCNNNN-Import-Module-VersionMap.md

You must be logged in to vote

Replies: 3 comments · 2 replies

Comment options

Overall, I appreciate the direction of introducing a lockfile. Having modules and their dependencies loaded into the default Assembly Load Context (ALC) enables effective sharing of dependencies and objects across modules.

However, further analysis is needed to validate whether isolating each loaded module within its own ALC would work reliably in all scenarios—particularly where cross-module object sharing is required. It is also important to assess whether this approach could introduce unnecessary runtime overhead or complexity.

You must be logged in to vote
1 reply
@et1975
Comment options

To clarify, when I'm talking about dependencies I only mean PS package dependencies, not whatever .NET assemblies they are dragging along.
In that regard I feel like the question of ALC is orthogonal to w/ or not a lockfile guides version resolution - whatever PS does under the hood with the DLLs to meet the lockfile spec could be opaque to the user because the lockfile does not need to mention assemblies, only packages.

Comment options

You must be logged in to vote
1 reply
@et1975
Comment options

  • If PSResourceGet implements it - great, if not... “¯_ (ツ)_/¯“ oh well, the problem of what to put on disk I have solved already.
    This is mostly about what happens after the modules are in the cache - guiding the otherwise optimistic resolution for import, precisely because local cache does change and things break when PS does heuristics instead of following a map.

  • As far as I can tell there are internals that are only available to powershell itself to make the import robust. As I've mentioned, I've hit an issue that I have not been able to properly reproduce or attribute when importing the dependency graph myself. I actually suspect that implementing it in powershell would be easier than outside as the module resolution can consult the map on demand (and only if provided) while following the existing logic, instead of rebuilding the load machinery, like I have to do.

@adityapatwardhan I'm willing to contribute the impl, assuming PS team agrees with this proposal in principle.

Comment options

Attached the RFC based on actual code findings instead my guesses.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.