-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Make GetWindowsPowerShellModulePath compatible with multiple PS installations #12280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
This is needed by #12269 |
src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs
Outdated
Show resolved
Hide resolved
|
@PoshChan please retry windows |
|
@daxian-dbw, successfully started retry of |
rjmholt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems reasonable if we accept that we're not engineering ourselves into a corner by doing yet more strange magic with the PSModulePath
test/powershell/Modules/Microsoft.PowerShell.Core/CompatiblePSEditions.Module.Tests.ps1
Show resolved
Hide resolved
| } | ||
| else | ||
| { | ||
| if (!File.Exists(Path.Combine(possiblePwshDir, "pwsh.exe"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be a nitpick here, but what if a parent PowerShell session starts with the FxDependent package where only pwsh.dll is present?
How about checking for pwsh.dll instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think about the powershell global tool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a need to consider things built with the SDK in general here too? Those will have a concept of the module path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good point. Updated to check for pwsh.dll.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. That seems to be right in terms of completeness, but I'm not sure if it's really necessary.
@SteveL-MSFT @anmenaga thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anmenaga All applications that built against Microsoft.PowerShell.SDK nuget package can potentially have modules Microsoft.PowerShell.Management and Microsoft.PowerShell.Utility in their $pshome\modules path. This is because we ship all built-in modules along with Microsoft.PowerShell.SDK since 7.0.
For example, PowerShell Jupyter kernel have all those built-in modules in the $pshome\modules folder.
With that being said, the real question is -- what is the chance to start pwsh from one of those applications (e.g. PS Jupyter) and then start powershell.exe from that pwsh? This feels unlikely to me. So I'm fine with just changing to pwsh.dll. @SteveL-MSFT can decide if we really want to go 100% completeness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every time I see once again a change in this code, I understand that I will never understand :-) why to be based on the variable change if this is a fundamentally insoluble problem in an SxS scenarios. What if there are several SDK applications in the row? There are an infinite number of application, modules and combinations.
And more tricky question: if PowerShell engine does the variable manipulation should all SDK applications follow the logic to get compatible behavior?
I still think it is better for PowerShell Engine to import/consume the variable values but does not export it - this should be delegated to applications/users who better know how address their specific scenario.
If we think about services, then everything becomes easier as there are independent processes. It is unclear why then complicate the behavior of subprocesses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iSazonov I personally agree with you, but the consensus is that we must proceed for now in a way that offers maximum compatibility with the existing concepts in PowerShell versions being used in the wild (particularly PS 5.1).
I worry that trying to nip and tuck the PSModulePath variable around other processes in the process stack is always going to have edge cases, but for something so fundamental to PowerShell this seems to be the more conservative option for now.
As for SDK embedding, I wonder if a scenario like Start-Job is going to be motivating. I'm not sure of what exact assemblies are published with the SDK, but we've defined $PSHome as where System.Management.Automation.dll lives and my thought is that perhaps that's the right assembly to anchor to...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally agree with you, but the consensus is
Thanks :-). For me it is a breaking change in grace area: nobody pointed me any affected critical scenario. I am amazed that team does not even start offer alternatives. My proposal was to expose $PSModulePath variable and GetPSModulePath() public method. Then 7.1 is nice milestone to remove these tricky PSModulePath env manipulations or make it opt-in. Otherwise, this behavior will always be problematic for years to come.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then 7.1 is nice milestone to remove these tricky PSModulePath env manipulations or make it opt-in. Otherwise, this behavior will always be problematic for years to come.
Very much agreed. I'm not sure we have this work on the board for the coming milestone, but I'll see if I can get the team to discuss it.
|
Do we want to have this in 7.0 Servicing? |
|
Probably yes; |
|
I moved to 7.0.x-Servicing-Consider to consider. |
|
🎉 Handy links: |
PR Summary
NativeCommandProcessorandWinCompatrely onGetWindowsPowerShellModulePathfunction to filter out PS-Core-specific module paths so that WindowsPS loads its own version of modules instead of PS-Core versions.However, when several side-by-side PS-Core installations (eg: MSI-installed, daily build, manual zip-based installation, etc...) started from each-other the filtering function does not work because it does not filter out the
$PSHOME\Modulesof the parent PS process.The fix is to add additional check for each component of PSModulePath (that is set for WinPS process) - if it is has
pwsh.exein the parent directory, then it is considered another PS Core installation and this location is also filtered out.Before the change:
After the change:
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.