diff --git a/src/Microsoft.PackageManagement/Implementation/ProviderServicesImpl.cs b/src/Microsoft.PackageManagement/Implementation/ProviderServicesImpl.cs index 6034776e8c..dc8a2e4c32 100644 --- a/src/Microsoft.PackageManagement/Implementation/ProviderServicesImpl.cs +++ b/src/Microsoft.PackageManagement/Implementation/ProviderServicesImpl.cs @@ -190,9 +190,14 @@ namespace Microsoft.PackageManagement.Internal.Implementation { public int StartProcess(string filename, string arguments, bool requiresElevation, out string standardOutput, IRequest requestObject) { Process p = new Process(); - if (requiresElevation) { +#if !CORECLR + if (requiresElevation) + { p.StartInfo.UseShellExecute = true; - } else { + } + else +#endif + { p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; } diff --git a/src/System.Management.Automation/help/HelpCommands.cs b/src/System.Management.Automation/help/HelpCommands.cs index ed8593d904..fe2be6fe3c 100644 --- a/src/System.Management.Automation/help/HelpCommands.cs +++ b/src/System.Management.Automation/help/HelpCommands.cs @@ -699,18 +699,17 @@ 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 = true; - if (Platform.IsWindows) - { - browserProcess.StartInfo.FileName = uriToLaunch.OriginalString; - } 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 2c83a4ea18..39c60e005b 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -1333,20 +1333,16 @@ namespace Microsoft.PowerShell.Commands { System.Diagnostics.Process invokeProcess = new System.Diagnostics.Process(); - if (Platform.IsWindows) - { - System.Diagnostics.Process.Start(path); - } - 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 efc9b7917c..bc16864990 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 @@ -2,14 +2,6 @@ using namespace System.Diagnostics Describe "Invoke-Item" { - $tmpDirectory = $TestDrive - $testfile = "testfile.txt" - $testfolder = "newDirectory" - $testlink = "testlink" - $FullyQualifiedFile = Join-Path -Path $tmpDirectory -ChildPath $testfile - $FullyQualifiedFolder = Join-Path -Path $tmpDirectory -ChildPath $testfolder - $FullyQualifiedLink = Join-Path -Path $tmpDirectory -ChildPath $testlink - function NewProcessStartInfo([string]$CommandLine, [switch]$RedirectStdIn) { return [ProcessStartInfo]@{ @@ -39,38 +31,20 @@ Describe "Invoke-Item" { } } - function Clean-State - { - if (Test-Path $FullyQualifiedLink) - { - Remove-Item $FullyQualifiedLink -Force - } - - if (Test-Path $FullyQualifiedFile) - { - Remove-Item $FullyQualifiedFile -Force - } - - if (Test-Path $FullyQualifiedFolder) - { - Remove-Item $FullyQualifiedFolder -Force - } - } - BeforeAll { $powershell = Join-Path -Path $PsHome -ChildPath "powershell" + Setup -File testfile.txt -Content "Hello World" + $testfile = Join-Path $TestDrive testfile.txt } -#Both tests are pending due to a bug in Invoke-Item on Windows. Fixed for Linux - - It "Should call the function without error" -Pending:$IsWindows { - { New-Item -Name $testfile -Path $tmpDirectory -ItemType file } | Should Not Throw - } - - It "Should invoke a text file without error" -Pending:$IsWindows { - $debugfn = NewProcessStartInfo "-noprofile ""``Invoke-Item $FullyQualifiedFile`n" -RedirectStdIn + 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." + } }