From 6200f084cd949358f11c25c8c0e6ed550e02343d Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 8 Jul 2016 09:20:58 -0700 Subject: [PATCH] Invoke-Item and Get-Help -Online are unsupported on Nano These currently fail at runtime on Nano, and will continue to do so. But this implements these much needed cmdlets for Open PowerShell. If there is a way to determine that PowerShell is being run on the Nano OS at runtime, then we could instead throw a platform unsupported exception, but this cannot be based on the target compilation framework, as .NET Core is shared for both Nano and Windows. --- .../help/HelpCommands.cs | 14 +++++++++++++- .../namespaces/FileSystemProvider.cs | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/help/HelpCommands.cs b/src/System.Management.Automation/help/HelpCommands.cs index 52a74fed07..b6f69d498a 100644 --- a/src/System.Management.Automation/help/HelpCommands.cs +++ b/src/System.Management.Automation/help/HelpCommands.cs @@ -704,8 +704,20 @@ namespace Microsoft.PowerShell.Commands if (Platform.IsWindows) { + // this is a re-implementation of the unavailable (on .NET Core) UseShellExecute, + // where we manually execute a cmd.exe shell, and use its start command to + // launch the default application for the given path browserProcess.StartInfo.FileName = "cmd.exe"; - browserProcess.StartInfo.Arguments = string.Format(@"/c ""start /b """" {0}""", uriToLaunch.OriginalString); + + // start is very picky: the "optional" TITLE as the first argument should always + // be included, otherwise it can silently fail + browserProcess.StartInfo.Arguments = string.Format(CultureInfo.InvariantCulture, + @"/c ""start /b """" {0}""", uriToLaunch.OriginalString); + + // please note that there is currently no way to differentiate between running + // on Nano as an OS and having targeted the .NET Core framework, thus this code + // will continue to fail on Nano (as there is no browser), but at least is + // implemented for .NET Core PowerShell on Windows } else if (Platform.IsOSX) { diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 7ee00beb27..2504bb3491 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -1337,9 +1337,20 @@ namespace Microsoft.PowerShell.Commands if (Platform.IsWindows) { + // this is a re-implementation of the unavailable (on .NET Core) UseShellExecute, + // where we manually execute a cmd.exe shell, and use its start command to + // launch the default application for the given path invokeProcess.StartInfo.FileName = "cmd.exe"; - // start is very picky: the "optional" TITLE as the first argument should always be included, otherwise it can silently fail - invokeProcess.StartInfo.Arguments = string.Format(@"/c ""start /b """" ""{0}""""", path); + + // start is very picky: the "optional" TITLE as the first argument should always + // be included, otherwise it can silently fail + invokeProcess.StartInfo.Arguments = string.Format(CultureInfo.InvariantCulture, + @"/c ""start /b """" ""{0}""""", path); + + // please note that there is currently no way to differentiate between running + // on Nano as an OS and having targeted the .NET Core framework, thus this code + // will continue to fail on Nano (as there is no browser), but at least is + // implemented for .NET Core PowerShell on Windows } else if (Platform.IsOSX) { invokeProcess.StartInfo.FileName = "open";