-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Preserve PSModulePath environment variable #10300
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
8000
src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs
Show resolved
Hide resolved
d50fdb6
to
a9a7676
Compare
Current issues with test:
@SteveL-MSFT @daxian-dbw @rjmholt @adityapatwardhan I hope you help. @mklement0 @KirkMunro @Jaykul for information. |
1de2f67
to
a33d439
Compare
That sounds like we have different expectations in different tests. Ideally we should fix that.
The Would you be able to describe the nature of this change @iSazonov? I understand the issues it addresses, and got some information from the description, but would you be able to write a paragraph at the top of the description describing:
|
I meant all 6.*. After 7.0 release 6.* will be out of support soon - it is not LTS version. And I suggest don't clean up the specific 6.* module path. (But we could address this if needed in follow PR. The problem here is that an user could want to preserve the path)
There is reworded PowerShell Committee conclusion in #9957 and original PowerShell/PowerShell-RFC#133 (comment) |
e2cacde
to
4a8a85d
Compare
@iSazonov after some discussion with @JamesWTruher on what we think is the right behavior, I'm going to author a small RFC |
Please take look at PowerShell/PowerShell-RFC#233, I'll submit a code PR to validate my logic |
@SteveL-MSFT I have take look the RFC. I see you consider only SxS for Core vs Windows PowerShell, not third-party soft. In the case my proposal resolve all the SxS scenarios in simplest way. I still don't understand why we should expose modified PSModulePath environment variable. If needed for UX and scripts we could introduce |
@iSazonov we modify |
What is the utilities? |
@iSazonov I don't have any specific utilities in mind, but a search on GitHub shows lots of scripts manipulating $env:PSModulePath |
@SteveL-MSFT I see that they add custom paths but not extract "system"/PowerShell paths. |
@SteveL-MSFT Thanks! I hope the long story is resolved now for years :-) |
PR Summary
Fix #9957
Fix #9921
Fix #7082
Fix #6850
Fix #10620
For reference #9845
The fix was approved by PowerShell Committee.
The fix is that now we do not change PSModulePath environment variable. Now we only read it and add to a module path cache. Also we add Powershell standard paths in the cache.
Because now we don't change PSModulePath environment variable we have no needs to manipulate strings and the module path cache is List<string>.
There was discovered some bugs. I hope they is related only tests.
We use
string.Contains()
but correct way is to use PathContainsSubstring()PowerShell/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs 8000
Lines 1357 to 1363 in 17fb524
As result the system path was not added in tests because we added a module path like c:\tmp\root\modulename then we were tried to add c:\tmp\root (come from test hook) but string.Contains() returns true.
We don't removed a root module in CompatiblePSEditions.Module.Tests.ps1
PowerShell/test/powershell/Modules/Microsoft.PowerShell.Core/CompatiblePSEditions.Module.Tests.ps1
Lines 735 to 738 in 17fb524
As result some tests below failed after the PR fix. I hope it is only test issue - please review in depth.
Perhaps it is not bug but we need a conclusion. If we add a path to module in PSModulePath and then add a root path from the module path like c:\tmp\root\modulename and c:\tmp\root - Get-Module -Listavailable -All returns the module twice. (No regression - Windows PowerShell works the same way.)
The PR fix doesn't remove path to PSHome/Module if 7.0 starts from 6.0:

I think it makes no sense to remove the path because 6.0 will deprecated (EOL) soon.
PR Context
See #9957
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.