diff --git a/src/System.Management.Automation/help/HelpCommands.cs b/src/System.Management.Automation/help/HelpCommands.cs index b6f69d498a..fe2be6fe3c 100644 --- a/src/System.Management.Automation/help/HelpCommands.cs +++ b/src/System.Management.Automation/help/HelpCommands.cs @@ -700,37 +700,16 @@ namespace Microsoft.PowerShell.Commands this.WriteVerbose(string.Format(CultureInfo.InvariantCulture, HelpDisplayStrings.OnlineHelpUri, uriToLaunch.OriginalString)); System.Diagnostics.Process browserProcess = new System.Diagnostics.Process(); - browserProcess.StartInfo.UseShellExecute = false; - - 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"; - - // 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) - { - browserProcess.StartInfo.FileName = "open"; - browserProcess.StartInfo.Arguments = uriToLaunch.OriginalString; - } - else if (Platform.IsLinux) - { - browserProcess.StartInfo.FileName = "xdg-open"; - browserProcess.StartInfo.Arguments = uriToLaunch.OriginalString; - } - +#if LINUX + browserProcess.StartInfo.FileName = Platform.IsLinux ? "xdg-open" : /* OS X */ "open"; + browserProcess.StartInfo.Arguments = uriToLaunch.OriginalString; browserProcess.Start(); +#elif CORECLR + throw new PlatformNotSupportedException(); +#else + browserProcess.StartInfo.FileName = uriToLaunch.OriginalString; + browserProcess.Start(); +#endif } catch (InvalidOperationException ioe) { diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 2504bb3491..39c60e005b 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -1333,35 +1333,16 @@ namespace Microsoft.PowerShell.Commands { System.Diagnostics.Process invokeProcess = new System.Diagnostics.Process(); - invokeProcess.StartInfo.UseShellExecute = false; - - 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(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"; - invokeProcess.StartInfo.Arguments = path; - } - else if (Platform.IsLinux) { - invokeProcess.StartInfo.FileName = "xdg-open"; - invokeProcess.StartInfo.Arguments = path; - } - +#if LINUX + invokeProcess.StartInfo.FileName = Platform.IsLinux ? "xdg-open" : /* OS X */ "open"; + invokeProcess.StartInfo.Arguments = path; invokeProcess.Start(); +#elif CORECLR + throw new PlatformNotSupportedException(); +#else + invokeProcess.StartInfo.FileName = path; + invokeProcess.Start(); +#endif } } // InvokeDefaultAction diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 index f17a716959..bc16864990 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 @@ -37,10 +37,14 @@ Describe "Invoke-Item" { $testfile = Join-Path $TestDrive testfile.txt } - It "Should invoke a text file without error" { + It "Should invoke a text file without error" -Skip:($IsWindows -and $IsCore) { $debugfn = NewProcessStartInfo "-noprofile ""``Invoke-Item $testfile`n" -RedirectStdIn $process = RunPowerShell $debugfn EnsureChildHasExited $process $process.ExitCode | Should Be 0 } + + It "Should throw not supported on Windows with .NET Core" -Skip:($IsLinux -or $IsOSX -or !$IsCore) { + { Invoke-Item $testfile }| Should Throw "Operation is not supported on this platform." + } }