-
Notifications
You must be signed in to change notification settings - Fork 511
$PROFILE
variable has changed type and behavior
#3653
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
Needs to be a PSObject profile = PSObject.AsPSObject("C:\CurrentUserCurrentHostPathEtc");
profile.Properties.Add(new PSNoteProperty("AllUsersAllHosts", "pathhere"));
profile.Properties.Add(new PSNoteProperty("AllUsersCurrentHost", "pathhere"));
profile.Properties.Add(new PSNoteProperty("CurrentUserAllHosts", "pathhere"));
profile.Properties.Add(new PSNoteProperty("CurrentUserCurrentHost", "pathhere")); |
This is inconsistent with Try this in a regular PS console. PS>$PROFILE.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
PS>$PROFILE | Get-Member
TypeName: System.String
Name MemberType Definition
---- ---------- ----------
[...]
AllUsersAllHosts NoteProperty string AllUsersAllHosts=C:\Program Files\PowerShell\7\profile.ps1
AllUsersCurrentHost NoteProperty string AllUsersCurrentHost=C:\Program Files\PowerShell\7\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts NoteProperty string CurrentUserAllHosts=C:\Users\sburbano\Documents\PowerShell\profile.ps1
CurrentUserCurrentHost NoteProperty string CurrentUserCurrentHost=C:\Users\sburbano\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
[...] May be pwsh.exe is doing something under the covers or treating PS>$test = "Some string"
PS>$test.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
PS>Add-Member -InputObject $test -NotePropertyName "SomeProperty" -NotePropertyValue "SomeValue"
PS>Get-Member -InputObject $test
TypeName: System.String
Name MemberType Definition
---- ---------- ----------
[ ommitted for brevity, but NO SomeProperty] |
Just for the sake of completeness... This is even mentioned in the official documentation |
@sburbano strings are unfortunately very complicated when it comes to ETS properties. When handled in C#, it's pretty simple since no PowerShell engine magic gets in the way. In PowerShell you gotta be a bit explicit. More specifically the first line needs to be: $test = [psobject]"Some string" So typically any reference type object has it's manually added ETS members preserved between Strings specifically are special cased to work a bit more like primitives/other structs (most likely because they are immutable and can be interned). So if you want to add ETS members to a string you must preserve the In general that's not super feasible to do which is why I typically tell folks to just not do it, but it works fine for a automatic variable (and it's what SMA's |
@SeeminglyScience Wow!! I see! PS>$test = [psobject]"Some string"
PS>$test.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
PS>Add-Member -InputObject $test -NotePropertyName "SomeProperty" -NotePropertyValue "Some value"
PS>Get-Member -InputObject $test
TypeName: System.String
Name MemberType Definition
---- ---------- ----------
[...]
SomeProperty NoteProperty string SomeProperty=Some value PS is like a box of chocolates... 😄 |
Yeah One thing that never lies (currently) though is It gets very confusing but thankfully it doesn't come up as a problem unless you look real close 😁 |
$PROFILE
variable has changed type and behavior
This issue has been marked as fixed. It has been automatically closed for housekeeping purposes. |
Prerequisites
Summary
Since updating to the latest preview, the $PROFILE variable in the Integrated Console has changed its type, from String to PSCustomObject.
Before:
After:
This change in type also changes the way the variable is coerced to other types, output to console etc possibly breaking any script that use this variable.
Before:
After:
In my case, for example, custom theme loading in the profile has stopped working, because this function has stopped working.
Might be related to #3650
PowerShell Version
Visual Studio Code Version
Extension Version
[email protected]
Steps to Reproduce
Compare the output of
in the PS Integrated Console and any other Powershell Console (regular pwsh.exe, Windows Terminal, ...)
Visuals
No response
Logs
No response
The text was updated successfully, but these errors were encountered: