Skip to content

$PROFILE is NULL when invoking profile.ps1 and Microsoft.VSCode_profile.ps1 #3662

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

Closed
5 tasks done
Liturgist opened this issue Nov 2, 2021 · 3 comments
Closed
5 tasks done
Labels
Issue-Bug A bug to squash. Resolution-Duplicate Will close automatically.

Comments

@Liturgist
Copy link

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.

Summary

Here is the output in the TERMINAL window when VSCode PowerShell extension starts. The profile scripts are shown below. When the CurrentUserAllHosts script is run, $PROFILE is NULL. None of these scripts set the value of $PROFILE.

There are two (2) problems.

When one of the non-user profile scripts is invoked (probably AllUsersAllHosts), it appears that the path to the script does not use appropriately placed QUOTATION MARK characters.

When the CurrentUserAllHosts script is run, $PROFILE is NULL.

=====> PowerShell Preview Integrated Console v2021.10.3 <=====

C:\Program: The term 'C:\Program' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Running profile C:\Users\lit\Documents\PowerShell\profile.ps1
PROFILE is NULL
PS C:\Users\lit>

When the TERMINAL command prompt becomes available, the PROFILE variable now contains the following.

PS C:\Users\lit> $PROFILE | Format-List -Property *

AllUsersAllHosts       : C:\Program Files\PowerShell\7\profile.ps1
AllUsersCurrentHost    : C:\Program Files\PowerShell\7\Microsoft.VSCode_profile.ps1
CurrentUserAllHosts    : C:\Users\lit\Documents\PowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\lit\Documents\PowerShell\Microsoft.VSCode_profile.ps1

These are the profile scripts. Note that both of the Microsoft.VSCode_profile.ps1 files do not exist.

PS C:\> Get-Content -Path 'C:\Program Files\PowerShell\7\profile.ps1'
$s = $($MyInvocation.MyCommand.Source)
Write-Host "Running profile $s"
if ($null -eq $PROFILE) {
    Write-Host "PROFILE is NULL"
} else {
    Write-Host "PROFILE is of type $($PROFILE.GetType())"

    $scope = $PROFILE |
        Get-Member -Type NoteProperty |
        Where-Object { $_.Definition.EndsWith($s) } |
        ForEach-Object { $_.Name }
    Write-Host "$($PSVersionTable.PSVersion.ToString()) $scope @ $($MyInvocation.MyCommand.Source)"
}
PS C:\> Get-Content -Path 'C:\Program Files\PowerShell\7\Microsoft.VSCode_profile.ps1'
Get-Content: Cannot find path 'C:\Program Files\PowerShell\7\Microsoft.VSCode_profile.ps1' because it does not exist.
PS C:\> Get-Content -Path 'C:\Users\lit\Documents\PowerShell\profile.ps1'
$s = $($MyInvocation.MyCommand.Source)
Write-Host "Running profile $s"
if ($null -eq $PROFILE) {
    Write-Host "PROFILE is NULL"
} else {
    Write-Host "PROFILE is of type $($PROFILE.GetType())"

    $scope = $PROFILE |
        Get-Member -Type NoteProperty |
        Where-Object { $_.Definition.EndsWith($s) } |
        ForEach-Object { $_.Name }
    Write-Host "$($PSVersionTable.PSVersion.ToString()) $scope @ $($MyInvocation.MyCommand.Source)"
}
PS C:\> Get-Content -Path 'C:\Users\lit\Documents\PowerShell\Microsoft.VSCode_profile.ps1'
Get-Content: Cannot find path 'C:\Users\lit\Documents\PowerShell\Microsoft.VSCode_profile.ps1' because it does not exist.
PS C:\>

PowerShell Version

PS C:\> $PSVersionTable

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

Visual Studio Code Version

PS C:\> code --version
1.61.2
6cba118ac49a1b88332f312a8f67186f7f3c1643
x64

Extension Version

PS C:\> code --list-extensions --show-versions | Select-String powershell

[email protected]
[email protected]

Steps to Reproduce

Start VSCode powershell extension with profile scripts included above.

Visuals

No response

Logs

No response

@Liturgist Liturgist added the Issue-Bug A bug to squash. label Nov 2, 2021
@ghost ghost added the Needs: Triage Maintainer attention needed! label Nov 2, 2021
@rob-peck-wiggle
Copy link

I can confirm similar behaviour here - it will not load profiles with spaces in the path when using PowerShell Preview extension. I moved back to PowerShell stable extension and the issue goes away.

@Liturgist
Copy link
Author

Rob, thanks for confirming. I have forgotten why, but there was something that the stable version did not do that caused me to use the preview version. Going back to stable may not be a workaround.

I can confirm similar behaviour here - it will not load profiles with spaces in the path when using PowerShell Preview extension. I moved back to PowerShell stable extension and the issue goes away.

@andyleejordan
Copy link
Member

Thanks for the bug report! Going to mark this as duplicate as it's reported here too: #3650 (comment)

We totally broke profile loading in the Preview, sorry! Working on fixing and covering with regression tests.

@andyleejordan andyleejordan added Resolution-Duplicate Will close automatically. and removed Needs: Triage Maintainer attention needed! labels Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug A bug to squash. Resolution-Duplicate Will close automatically.
Projects
None yet
Development

No branches or pull requests

3 participants