Throw PlatformNotSupported on Windows .NET Core build

This commit is contained in:
Andrew Schwartzmeyer
2016-07-08 14:08:22 -07:00
parent 6200f084cd
commit 50e6627a8e
3 changed files with 23 additions and 59 deletions
@@ -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)
{
@@ -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
@@ -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."
}
}