diff --git a/module/PowerShellEditorServices/Start-EditorServices.ps1 b/module/PowerShellEditorServices/Start-EditorServices.ps1 index 499bf816f..08f9e1bc4 100644 --- a/module/PowerShellEditorServices/Start-EditorServices.ps1 +++ b/module/PowerShellEditorServices/Start-EditorServices.ps1 @@ -161,6 +161,21 @@ if ($host.Runspace.LanguageMode -eq 'ConstrainedLanguage') { ExitWithError "PowerShell is configured with an unsupported LanguageMode (ConstrainedLanguage), language features are disabled." } +# net45 is not supported, only net451 and up +if ($PSVersionTable.PSVersion.Major -le 5) { + $net451Version = 378675 + $dotnetVersion = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\").Release + if ($dotnetVersion -lt $net451Version) { + Write-SessionFile @{ + status = failed + reason = "netversion" + detail = "$netVersion" + } + + ExitWithError "Your .NET version is too low. Upgrade to net451 or higher to run the PowerShell extension." + } +} + # If PSReadline is present in the session, remove it so that runspace # management is easier if ((Microsoft.PowerShell.Core\Get-Module PSReadline).Count -gt 0) { diff --git a/src/PowerShellEditorServices.Host/EditorServicesHost.cs b/src/PowerShellEditorServices.Host/EditorServicesHost.cs index 503e03068..516b0bba9 100644 --- a/src/PowerShellEditorServices.Host/EditorServicesHost.cs +++ b/src/PowerShellEditorServices.Host/EditorServicesHost.cs @@ -154,6 +154,8 @@ public void StartLogging(string logFilePath, LogLevel logLevel) string osVersion = RuntimeInformation.OSDescription; + string osArch = GetOSArchitecture(); + string buildTime = BuildInfo.BuildTime?.ToString("s", System.Globalization.CultureInfo.InvariantCulture) ?? ""; string logHeader = $@" @@ -164,12 +166,12 @@ public void StartLogging(string logFilePath, LogLevel logLevel) Name: {this.hostDetails.Name} Version: {this.hostDetails.Version} ProfileId: {this.hostDetails.ProfileId} - Arch: {RuntimeInformation.OSArchitecture} + Arch: {osArch} Operating system details: Version: {osVersion} - Arch: {RuntimeInformation.OSArchitecture} + Arch: {osArch} Build information: @@ -245,7 +247,7 @@ await this.editorSession.PowerShellContext.ImportCommandsModule( // gets initialized when that is done earlier than LanguageServer.Initialize foreach (string module in this.additionalModules) { - var command = + var command = new System.Management.Automation.PSCommand() .AddCommand("Microsoft.PowerShell.Core\\Import-Module") .AddParameter("Name", module); @@ -493,6 +495,28 @@ private IServerListener CreateServiceListener(MessageProtocolType protocol, Edit } } + /// + /// Gets the OSArchitecture for logging. Cannot use System.Runtime.InteropServices.RuntimeInformation.OSArchitecture + /// directly, since this tries to load API set DLLs in win7 and crashes. + /// + /// + private string GetOSArchitecture() + { +#if !CoreCLR + // If on win7 (version 6.1.x), avoid System.Runtime.InteropServices.RuntimeInformation + if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version < new Version(6, 2)) + { + if (Environment.Is64BitProcess) + { + return "X64"; + } + + return "X86"; + } +#endif + return RuntimeInformation.OSArchitecture.ToString(); + } + #endregion } }