-
Notifications
You must be signed in to change notification settings - Fork 511
Using enableProfileLoading to modify PSModulePath does not persist. #1122
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
Comments
Hi there, thanks for this! Can you tell me which profile you're adding this line to? I believe (@rkeithhill + @daviwil please correct me if I'm wrong), the extension only loads:
if you specify |
It should also load the
And I can't repro this. If I put the following into the Write-Warning "Executing $($MyInvocation.MyCommand.Name)"
$env:PSModulePath = $env:PSModulePath + ";c:\ModulePath" and then restart my session, I get this:
However the bit about the extension's modification to the path being missing is troubling. Which profile are you putting the PSModulePath modification in? The vscode-powershell/scripts/Start-EditorServices.ps1 Lines 185 to 188 in 93bc21c
I wonder if one of your profiles is accidentally whacking PSModulePath to its default?? Could you dump the contents of the four profiles listed above and see what modifications are being made to $env:PSModulePath? |
BTW one of the things I'd like to see is an init script for your workspace so that you could import just the modules needed to drive auto-completion for that workspace. Something like |
@rkeithhill I am using the Microsoft.VSCode_profile.ps1 file you mentioned, in the .../Documents/PowerShell/ directory. Also I did narrow down the issue cause. It only blows away the path when the directory I append to the PSModulePath is the same as the VS Code workspace. i.e. Using current workspace in profile gives me a path like this (using C:\dev\workspace in profile):
Using a different folder that is not my workspace gives me something like this (using C:\dev in profile):
Let me know if you need anymore details. Is that init script something that has been discussed? Because I could see that being fairly useful. |
Yes I am modifying the correct file. I am going to do some more testing on my end. It looks like it might be related to my workspace in particular, perhaps it's related to some setting or something with Git. |
Well I have no idea what is going on. If I copy my entire directory tree to a new location and open the workspace on the copy, the issue does not happen. But if I put a new copy in the same root folder the issue shows up, only in this one folder does it happen. If I move it one folder higher or one deeper the issue does not happen.... For example C:\dev\MyRepos\ breaks, C:\dev\ works and C:\dev\MyRepos\Test works. Anything checked out into C:\dev\MyRepos\ and opened in VS Code causes this issue to occur if the profile changes the PSModulePath to contain that directory. If I change "MyRepos" to a different name the issue also goes away. One final note, not surprisingly this is also unique to a single machine, copying the same directory structure to a new computer does not reproduce the issue. Let me know if there is any thing you'd like to me do before I purge/rename the existing folder to make the issues go away. |
Is that directory a junction/mount point or anything else weird like that? The other thing that would be good to know is if this happens in pure PowerShell Core - no VSCode. |
Nothing special about it that I can think of. It's just a folder I created to check out repos from my Stash/Bitbucket Server profile. The only thing "different" about it is that it contains Git checkouts. Do you mean using a regular non-VSCode PowerShell profile? It works fine, that's how I've been able to use my modules in PowerShell Core. |
@rkeithhill Good news! I discovered how to reproduce the issue. This only occurs if you have a User/System Environment Variable defined for PSModulePath. I had done this for PowerShell 5.1. I have a User Environment Variable defined for PSModulePath = C:\dev\MyRepos\Workspace via Advanced system settings -> Environment Variables, and then have an entry in the Microsoft.VSCode_profile.ps1 for $Env:PSModulePath = $Env:PSModulePath + ';C:\dev\MyRepos\Workspace'. I have tested this on a new machine and the issue is repeatable. Whether or not this is a good idea is debatable... and it is still odd that it only seems to effect the Integrated Console. |
Fascinating... did you ever try this in the ISE to see what happens? |
Doesn't the ISE only work with Windows PowerShell? This bug only shows up with the integrated console with PowerShell Core. |
Ah yes. My bad. You said
and thought the issue was with 5.1. :) So when you remove that User/System Environment Variable the issue disappears? |
Something weird going on indeed. AFAICT, PS Core doesn't reflect the PSModulePath change I made to my USER PATH env var. I instrumented my PS Core MS.VSCode profile to display PSModulePath before and after and it looks like everything is fine:
But when I inspect the final PSModulePath, two paths are missing:
Hmm, time to look into this some more. |
@tylerl0706 Yes, removing the pre-set variable fixes the issue after you restart the console. @rkeithhill Yes, I was seeing the same thing, the profile has the correct value, but somewhere between there and the console fully loading the value gets defaulted back the original value. Also since PowerShell Core does not load the windows PSModulePath, I find it very strange that a system/user variable that Core is ignoring correctly (which we can see in the profile output) is somehow interfering with the integrated console and causing it to reset the value of the variable. |
OK this might be caused by PS Core: if (!string.IsNullOrEmpty(currentProcessModulePath) &&
NeedToClearProcessModulePath(currentProcessModulePath, personalModulePath, sharedModulePath, runningSxS))
{
// Clear the current process module path in the following cases
// - start sxs ps on windows [machine-wide env:PSModulePath will influence]
// - start sxs ps from full ps
// - start sxs ps from inbox nano/iot ps
// - start full ps from sxs ps
// - start inbox nano/iot ps from sxs ps
currentProcessModulePath = null;
} You don't normally see this problem in PS Core but with the VSCode extension, PS Core is started, a script is run to import and start PSES. At this point the env var is correct. However,once PSES starts executing it has to set up its PSHost UI and I "think" in the process of doing that, the above code is executed which resets the PSModulePath. I haven't had a chance to verify this yet in the debugger. It's a theory at this point. If this is the case, perhaps we can stash and restore the PSModulePath in PSES. |
@SydneyhSmith @TylerLeonhardt I wasn't able to reproduce per #1122 (comment)
write-host -fore yellow "Before: $ENV:PSMODULEPATH"
$ENV:PSMODULEPATH = $ENV:PSMODULEPATH + ';C:\Users\JGrote\Desktop'
write-host -fore green "After: $ENV:PSMODULEPATH" |
Issue Description
If I enable profile loading and in a profile put the line
$Env:PSModulePath = $Env:PSModulePath + ';<CUSTOM_PATH>'
and launch VS Code, after the integrated terminal loads, the new path does not exist andC:\Users\<User>\.vscode\extensions\ms-vscode.powershell-1.5.1\modules
is missing. Note that other environment variables I set still exist.Environment Information
Visual Studio Code
PowerShell Information
Visual Studio Code Extensions
Visual Studio Code Extensions(Click to Expand)
The text was updated successfully, but these errors were encountered: