From a8fcada43f1a2fe63c7312176dd2e5862a15a97a Mon Sep 17 00:00:00 2001 From: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> Date: Thu, 10 Aug 2023 17:25:50 -0700 Subject: [PATCH] Fix shell integration for PowerShell 5.1 with strict mode Since `$IsWindows` doesn't exist in Windows PowerShell, with strict mode enabled and the `ErrorActionPreference` set to `Stop`, shell integration would cause the startup to crash. This was reported and fixed upstream too. --- .../Services/PowerShell/Host/PsesInternalHost.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs index a737cf1d9..e6f85ca78 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs @@ -663,7 +663,11 @@ private Task EnableShellIntegrationAsync(CancellationToken cancellationToken) } # Set IsWindows property -Write-Host -NoNewLine ""$([char]0x1b)]633;P;IsWindows=$($IsWindows)`a"" +if ($PSVersionTable.PSVersion -lt ""6.0"") { + [Console]::Write(""$([char]0x1b)]633;P;IsWindows=$true`a"") +} else { + [Console]::Write(""$([char]0x1b)]633;P;IsWindows=$IsWindows`a"") +} # Set always on key handlers which map to default VS Code keybindings function Set-MappedKeyHandler {