diff --git a/src/PowerShellEditorServices/Session/PowerShellContext.cs b/src/PowerShellEditorServices/Session/PowerShellContext.cs index 2284a99ff..fbfe46cb2 100644 --- a/src/PowerShellEditorServices/Session/PowerShellContext.cs +++ b/src/PowerShellEditorServices/Session/PowerShellContext.cs @@ -34,14 +34,12 @@ namespace Microsoft.PowerShell.EditorServices /// public class PowerShellContext : IDisposable, IHostSupportsInteractiveSession { - private const string DotNetFrameworkDescription = ".NET Framework"; - private static readonly Action s_runspaceApartmentStateSetter; static PowerShellContext() { // PowerShell ApartmentState APIs aren't available in PSStandard, so we need to use reflection - if (RuntimeInformation.FrameworkDescription.Equals(DotNetFrameworkDescription)) + if (!Utils.IsNetCore) { MethodInfo setterInfo = typeof(Runspace).GetProperty("ApartmentState").GetSetMethod(); Delegate setter = Delegate.CreateDelegate(typeof(Action), firstArgument: null, method: setterInfo); @@ -195,7 +193,7 @@ public static Runspace CreateRunspace(PSHost psHost) // Windows PowerShell must be hosted in STA mode // This must be set on the runspace *before* it is opened - if (RuntimeInformation.FrameworkDescription.Equals(DotNetFrameworkDescription)) + if (s_runspaceApartmentStateSetter != null) { s_runspaceApartmentStateSetter(runspace, ApartmentState.STA); } diff --git a/src/PowerShellEditorServices/Utility/ExecutionTimer.cs b/src/PowerShellEditorServices/Utility/ExecutionTimer.cs index 994f83d27..2634eb6eb 100644 --- a/src/PowerShellEditorServices/Utility/ExecutionTimer.cs +++ b/src/PowerShellEditorServices/Utility/ExecutionTimer.cs @@ -1,3 +1,8 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + using System; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/src/PowerShellEditorServices/Utility/Logging.cs b/src/PowerShellEditorServices/Utility/Logging.cs index 6813feacb..4813789d3 100644 --- a/src/PowerShellEditorServices/Utility/Logging.cs +++ b/src/PowerShellEditorServices/Utility/Logging.cs @@ -1,3 +1,8 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + using System; using System.Collections.Generic; using Serilog; diff --git a/src/PowerShellEditorServices/Utility/PsesLogger.cs b/src/PowerShellEditorServices/Utility/PsesLogger.cs index e7dd29e9e..de257f556 100644 --- a/src/PowerShellEditorServices/Utility/PsesLogger.cs +++ b/src/PowerShellEditorServices/Utility/PsesLogger.cs @@ -1,3 +1,8 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + using System; using System.Runtime.CompilerServices; using System.Text; diff --git a/src/PowerShellEditorServices/Utility/Utils.cs b/src/PowerShellEditorServices/Utility/Utils.cs new file mode 100644 index 000000000..05787be43 --- /dev/null +++ b/src/PowerShellEditorServices/Utility/Utils.cs @@ -0,0 +1,21 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Runtime.InteropServices; + +namespace Microsoft.PowerShell.EditorServices +{ + /// + /// General purpose common utilities to prevent reimplementation. + /// + internal static class Utils + { + /// + /// True if we are running on .NET Core, false otherwise. + /// + public static bool IsNetCore { get; } = RuntimeInformation.FrameworkDescription.StartsWith(".NET Core", StringComparison.Ordinal); + } +}