diff --git a/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs b/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs index 5a7166eef..f2da0eb4e 100644 --- a/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs +++ b/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs @@ -32,6 +32,7 @@ namespace Microsoft.PowerShell.EditorServices.Hosting public sealed class EditorServicesLoader : IDisposable { #if !CoreCLR + // TODO: Well, we're saying we need 4.8 here but we're building for 4.6.2... // See https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed private const int Net48Version = 528040; @@ -342,7 +343,7 @@ private void LogHostInformation() _logger.Log(PsesLogLevel.Verbose, $@" == Environment Details == - OS description: {RuntimeInformation.OSDescription} - - OS architecture: {GetOSArchitecture()} + - OS architecture: {RuntimeInformation.OSArchitecture} - Process bitness: {(Environment.Is64BitProcess ? "64" : "32")} "); } @@ -355,27 +356,6 @@ private static string GetPSOutputEncoding() useLocalScope: true).Invoke()[0]; } - // TODO: Deduplicate this with VersionUtils. - private static string GetOSArchitecture() - { -#if CoreCLR - if (Environment.OSVersion.Platform != PlatformID.Win32NT) - { - return RuntimeInformation.OSArchitecture.ToString(); - } -#endif - - // If on win7 (version 6.1.x), avoid System.Runtime.InteropServices.RuntimeInformation - if (Environment.OSVersion.Version < new Version(6, 2)) - { - return Environment.Is64BitProcess - ? "X64" - : "X86"; - } - - return RuntimeInformation.OSArchitecture.ToString(); - } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2208:Instantiate argument exceptions correctly", Justification = "Checking user-defined configuration")] private void ValidateConfiguration() { diff --git a/src/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.csproj b/src/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.csproj index 2624f1ddf..bea365c3b 100644 --- a/src/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.csproj +++ b/src/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.csproj @@ -9,10 +9,6 @@ Debug;Release - - $(DefineConstants);CoreCLR - - 1591,1573,1572 diff --git a/src/PowerShellEditorServices/PowerShellEditorServices.csproj b/src/PowerShellEditorServices/PowerShellEditorServices.csproj index 315bf696e..a344b3401 100644 --- a/src/PowerShellEditorServices/PowerShellEditorServices.csproj +++ b/src/PowerShellEditorServices/PowerShellEditorServices.csproj @@ -9,9 +9,12 @@ Debug;Release - - $(DefineConstants);CoreCLR - + diff --git a/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs b/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs index b96beae9e..c7a983bd8 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs @@ -106,7 +106,8 @@ private IReadOnlyList ExecuteNormally(CancellationToken cancellationTok { _psCommand.AddOutputCommand(); - // Fix the transcription bug! + // Fix the transcription bug! Here we're fixing immediately before the invocation of + // our command, that has had `Out-Default` added to it. if (!_pwsh.Runspace.RunspaceIsRemote) { _psesHost.DisableTranscribeOnly(); @@ -282,6 +283,14 @@ private IReadOnlyList ExecuteInDebugger(CancellationToken cancellationT { _pwsh.Streams.Error.Clear(); } + + // Fix the transcription bug! Since we don't depend on `Out-Default` for + // `ExecuteDebugger`, we fix the bug here so the original invocation (before the + // script is executed) is good to go. + if (!_pwsh.Runspace.RunspaceIsRemote) + { + _psesHost.DisableTranscribeOnly(); + } } _psesHost.DebugContext.ProcessDebuggerResult(debuggerResult); diff --git a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs index a94406e4c..a737cf1d9 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs @@ -39,7 +39,6 @@ internal class PsesInternalHost : PSHost, IHostSupportsInteractiveSession, IRuns private static readonly PropertyInfo s_scriptDebuggerTriggerObjectProperty; -#if !CoreCLR /// /// To workaround a horrid bug where the `TranscribeOnly` field of the PSHostUserInterface /// can accidentally remain true, we have to use a bunch of reflection so that )Delegate.CreateDelegate( typeof(Action), transcribeOnlySetMethod); - s_executionContextProperty = typeof(System.Management.Automation.Runspaces.Runspace) + s_executionContextProperty = typeof(Runspace) .GetProperty("ExecutionContext", BindingFlags.NonPublic | BindingFlags.Instance); s_internalHostProperty = s_executionContextProperty.PropertyType .GetProperty("InternalHost", BindingFlags.NonPublic | BindingFlags.Instance); -#endif } public PsesInternalHost( @@ -544,23 +546,29 @@ public void InvokePSDelegate(string representation, ExecutionOptions executionOp // This works around a bug in PowerShell 5.1 (that was later fixed) where a running // transcription could cause output to disappear since the `TranscribeOnly` property was // accidentally not reset to false. -#pragma warning disable CA1822 // Warning to make it static when it's empty for CoreCLR. internal void DisableTranscribeOnly() -#pragma warning restore CA1822 { -#if !CoreCLR + if (VersionUtils.IsNetCore) + { + return; + } + // To fix the TranscribeOnly bug, we have to get the internal UI, which involves a lot // of reflection since we can't always just use PowerShell to execute `$Host.UI`. s_internalPSHostUserInterface ??= (s_internalHostProperty.GetValue( s_executionContextProperty.GetValue(CurrentPowerShell.Runspace)) - as PSHost).UI; + as PSHost)?.UI; + + if (s_internalPSHostUserInterface is null) + { + return; + } if (s_getTranscribeOnlyDelegate(s_internalPSHostUserInterface)) { s_setTranscribeOnlyDelegate(s_internalPSHostUserInterface, false); } -#endif } internal Task LoadHostProfilesAsync(CancellationToken cancellationToken) diff --git a/src/PowerShellEditorServices/Utility/VersionUtils.cs b/src/PowerShellEditorServices/Utility/VersionUtils.cs index f130039ee..85d6bb66b 100644 --- a/src/PowerShellEditorServices/Utility/VersionUtils.cs +++ b/src/PowerShellEditorServices/Utility/VersionUtils.cs @@ -42,11 +42,6 @@ internal static class VersionUtils /// public static bool IsPS5 { get; } = PSVersion.Major == 5; - /// - /// True if we are running in PowerShell Core 6, false otherwise. - /// - public static bool IsPS6 { get; } = PSVersion.Major == 6; - /// /// True if we are running in PowerShell 7, false otherwise. /// @@ -70,7 +65,7 @@ internal static class VersionUtils /// /// The .NET Architecture as a string. /// - public static string Architecture { get; } = PowerShellReflectionUtils.GetOSArchitecture(); + public static string Architecture { get; } = RuntimeInformation.OSArchitecture.ToString(); } internal static class PowerShellReflectionUtils @@ -117,24 +112,5 @@ internal static class PowerShellReflectionUtils public static string PSVersionString { get; } = s_psCurrentVersionProperty != null ? s_psCurrentVersionProperty.GetValue(null).ToString() : PSVersion.ToString(3); - - public static string GetOSArchitecture() - { -#if CoreCLR - if (Environment.OSVersion.Platform != PlatformID.Win32NT) - { - return RuntimeInformation.OSArchitecture.ToString(); - } -#endif - // If on win7 (version 6.1.x), avoid System.Runtime.InteropServices.RuntimeInformation - if (Environment.OSVersion.Version < new Version(6, 2)) - { - return Environment.Is64BitProcess - ? "X64" - : "X86"; - } - - return RuntimeInformation.OSArchitecture.ToString(); - } } } diff --git a/test/PowerShellEditorServices.Test.E2E/PowerShellEditorServices.Test.E2E.csproj b/test/PowerShellEditorServices.Test.E2E/PowerShellEditorServices.Test.E2E.csproj index a39126dd7..222250cf6 100644 --- a/test/PowerShellEditorServices.Test.E2E/PowerShellEditorServices.Test.E2E.csproj +++ b/test/PowerShellEditorServices.Test.E2E/PowerShellEditorServices.Test.E2E.csproj @@ -6,10 +6,6 @@ false - - $(DefineConstants);CoreCLR - -