vscode-powershell: Using enableProfileLoading to modify PSModulePath does not persist.

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 and C:\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

Name Version
Operating System Windows_NT x64 10.0.15063
VSCode 1.18.1
PowerShell Extension Version 1.5.1

PowerShell Information

Name Value
PSVersion 6.0.0-rc
PSEdition Core
GitCommitId v6.0.0-rc
OS Microsoft Windows 10.0.15063
Platform Win32NT
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.10032.0 6.0.0-rc
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)
Extension Author Version
code-spell-checker streetsidesoftware 1.5.1
markdown-all-in-one yzhang 0.11.2
mssql ms-mssql 1.2.1
PowerShell ms-vscode 1.5.1
vscode-eslint dbaeumer 1.4.3
xml DotJoshJohnson 1.9.2

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (3 by maintainers)

Most upvoted comments

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.

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.

Are you sure you modifying the profile in Documents\PowerShell instead of the one in Documents\WindowsPowerShell? I can’t repro this with PS Core 6.0.0-rc.

BTW, init script has been discussed here #190 and #880.