PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.71k stars 490 forks source link

Powershell profile not being loaded in terminal #5049

Closed flamableassassin closed 1 week ago

flamableassassin commented 1 month ago

Prerequisites

Summary

To get around https://github.com/PowerShell/PSResourceGet/issues/1494 I've been modifying $env:PSModulePath to include a folder where my modules are stored done using Save-Module. Due to the extension not loading my Powershell profile the env isn't being modified and is breaking access to modules.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.4.3
PSEdition                      Core 
GitCommitId                    7.4.3
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : Visual Studio Code Host
Version          : 2024.2.2
InstanceId       : 15edc23a-1b05-4c1c-bf82-ffc23928363a
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-GB
CurrentUICulture : en-GB
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

1.94.0-insider
527e41ff551bb1001d2f224c2dec2e2ea3b66832
x64

Extension Version

ms-vscode.powershell@2024.2.2

Steps to Reproduce

NaN

Visuals

No response

Logs

No response

o-l-a-v commented 2 weeks ago

You might have to use a different path for profile with vscode. See:

I use following paths for profile, which also loads in VSCode:

# PowerShell 6/7
[System.IO.Path]::Combine(
    [System.Environment]::GetFolderPath('MyDocuments'),
    'PowerShell',
    'Profile.ps1'
)

# Windows PowerShell 5.1
[System.IO.Path]::Combine(
    [System.Environment]::GetFolderPath('MyDocuments'),
    'WindowsPowerShell',
    'Profile.ps1'
)

Or you can modify $env:PSModulePath in user or system context, then a $profile is not needed.

# User context
[System.Environment]::SetEnvironmentVariable(
    'PSModulePath',
    '<value1>;<value2>',
    'User'
)

# System context
[System.Environment]::SetEnvironmentVariable(
    'PSModulePath',
    '<value1>;<value2>',
    'Machine'
)
flamableassassin commented 1 week ago

Well I missed the fact that my vscode profile was named Microsoft.VSCode_profile.ps1.ps1