From bb3555c3dc48cad365277dc7c045be1abf9c5ed6 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Thu, 26 May 2016 15:10:57 -0700 Subject: [PATCH] Fixed RemoteWindowsDeployer to copy dontet runtime to target server for enabling portable apps scenario --- .../RemotePSSessionHelper.ps1 | 12 +++++++++--- .../RemoteWindowsDeployer.cs | 13 +++++++++++++ .../RemoteWindowsDeploymentParameters.cs | 4 ++++ .../RemoteWindowsDeployer/StartServer.ps1 | 18 ++++++++++++++++-- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Testing/Deployers/RemoteWindowsDeployer/RemotePSSessionHelper.ps1 b/src/Microsoft.AspNetCore.Server.Testing/Deployers/RemoteWindowsDeployer/RemotePSSessionHelper.ps1 index b92fb3fe73..3089c798fd 100644 --- a/src/Microsoft.AspNetCore.Server.Testing/Deployers/RemoteWindowsDeployer/RemotePSSessionHelper.ps1 +++ b/src/Microsoft.AspNetCore.Server.Testing/Deployers/RemoteWindowsDeployer/RemotePSSessionHelper.ps1 @@ -9,6 +9,9 @@ param( [Parameter(Mandatory=$true)] [string]$accountPassword, + [Parameter(Mandatory=$false)] + [string]$dotnetRuntimePath = "", + [Parameter(Mandatory=$true)] [string]$executablePath, @@ -40,7 +43,7 @@ if ($serverAction -eq "StartServer") { Write-Host "Starting the application on machine '$serverName'" $startServerScriptPath = "$PSScriptRoot\StartServer.ps1" - $remoteResult=Invoke-Command -Session $psSession -FilePath $startServerScriptPath -ArgumentList $executablePath, $executableParameters, $serverType, $serverName, $applicationBaseUrl, $environmentVariables + $remoteResult=Invoke-Command -Session $psSession -FilePath $startServerScriptPath -ArgumentList $dotnetRuntimePath, $executablePath, $executableParameters, $serverType, $serverName, $applicationBaseUrl, $environmentVariables } else { @@ -54,5 +57,8 @@ Remove-PSSession $psSession # NOTE: Currenty there is no straight forward way to get the exit code from a remotely executing session, so # we print out the exit code in the remote script and capture it's output to get the exit code. -$finalExitCode=$remoteResult[$remoteResult.Length-1] -exit $finalExitCode \ No newline at end of file +if($remoteResult.Length > 0) +{ + $finalExitCode=$remoteResult[$remoteResult.Length-1] + exit $finalExitCode +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Testing/Deployers/RemoteWindowsDeployer/RemoteWindowsDeployer.cs b/src/Microsoft.AspNetCore.Server.Testing/Deployers/RemoteWindowsDeployer/RemoteWindowsDeployer.cs index 195f326528..fcc3e0f4bc 100644 --- a/src/Microsoft.AspNetCore.Server.Testing/Deployers/RemoteWindowsDeployer/RemoteWindowsDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.Testing/Deployers/RemoteWindowsDeployer/RemoteWindowsDeployer.cs @@ -53,6 +53,13 @@ namespace Microsoft.AspNetCore.Server.Testing " Account credentials are required to enable creating a powershell session to the remote server."); } + if (_deploymentParameters.ApplicationType == ApplicationType.Portable + && string.IsNullOrWhiteSpace(_deploymentParameters.DotnetRuntimePath)) + { + throw new ArgumentException($"Invalid value '{_deploymentParameters.DotnetRuntimePath}' for {nameof(RemoteWindowsDeploymentParameters.DotnetRuntimePath)}. " + + "It must be non-empty for portable apps."); + } + if (string.IsNullOrWhiteSpace(_deploymentParameters.RemoteServerFileSharePath)) { throw new ArgumentException($"Invalid value for {nameof(RemoteWindowsDeploymentParameters.RemoteServerFileSharePath)}." + @@ -155,6 +162,12 @@ namespace Microsoft.AspNetCore.Server.Testing parameterBuilder.Append($" -serverName {_deploymentParameters.ServerName}"); parameterBuilder.Append($" -accountName {_deploymentParameters.ServerAccountName}"); parameterBuilder.Append($" -accountPassword {_deploymentParameters.ServerAccountPassword}"); + + if (!string.IsNullOrEmpty(_deploymentParameters.DotnetRuntimePath)) + { + parameterBuilder.Append($" -dotnetRuntimePath \"{_deploymentParameters.DotnetRuntimePath}\""); + } + parameterBuilder.Append($" -executablePath \"{executablePath}\""); if (!string.IsNullOrEmpty(executableParameters)) diff --git a/src/Microsoft.AspNetCore.Server.Testing/Deployers/RemoteWindowsDeployer/RemoteWindowsDeploymentParameters.cs b/src/Microsoft.AspNetCore.Server.Testing/Deployers/RemoteWindowsDeployer/RemoteWindowsDeploymentParameters.cs index b8e5ab0f95..472c35a6f2 100644 --- a/src/Microsoft.AspNetCore.Server.Testing/Deployers/RemoteWindowsDeployer/RemoteWindowsDeploymentParameters.cs +++ b/src/Microsoft.AspNetCore.Server.Testing/Deployers/RemoteWindowsDeployer/RemoteWindowsDeploymentParameters.cs @@ -7,6 +7,7 @@ namespace Microsoft.AspNetCore.Server.Testing { public RemoteWindowsDeploymentParameters( string applicationPath, + string dotnetRuntimePath, ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture runtimeArchitecture, @@ -20,6 +21,7 @@ namespace Microsoft.AspNetCore.Server.Testing ServerName = remoteServerName; ServerAccountName = remoteServerAccountName; ServerAccountPassword = remoteServerAccountPassword; + DotnetRuntimePath = dotnetRuntimePath; } public string ServerName { get; } @@ -28,6 +30,8 @@ namespace Microsoft.AspNetCore.Server.Testing public string ServerAccountPassword { get; } + public string DotnetRuntimePath { get; } + /// /// The full path to the remote server's file share /// diff --git a/src/Microsoft.AspNetCore.Server.Testing/Deployers/RemoteWindowsDeployer/StartServer.ps1 b/src/Microsoft.AspNetCore.Server.Testing/Deployers/RemoteWindowsDeployer/StartServer.ps1 index 7bd8b2caa8..b3b390ae56 100644 --- a/src/Microsoft.AspNetCore.Server.Testing/Deployers/RemoteWindowsDeployer/StartServer.ps1 +++ b/src/Microsoft.AspNetCore.Server.Testing/Deployers/RemoteWindowsDeployer/StartServer.ps1 @@ -1,5 +1,8 @@ [CmdletBinding()] param( + [Parameter(Mandatory=$false)] + [string]$dotnetRuntimePath, + [Parameter(Mandatory=$true)] [string]$executablePath, @@ -31,8 +34,19 @@ IF (-Not [string]::IsNullOrWhitespace($environmentVariables)) } } -# Temporary workaround for issue https://github.com/dotnet/cli/issues/2967 -if ($executablePath -ne "dotnet.exe"){ +if ($executablePath -eq "dotnet.exe") +{ + Write-Host "Setting the dotnet runtime path to the PATH environment variable" + [Environment]::SetEnvironmentVariable("PATH", "$dotnetRuntimePath") +} + +Write-Host "Copying shell32.dll as a temporary workaround for issue https://github.com/dotnet/cli/issues/2967" +if ($executablePath -eq "dotnet.exe") +{ + Copy-Item C:\Windows\System32\forwarders\shell32.dll $dotnetRuntimePath +} +else +{ $destinationDir = Split-Path $executablePath Copy-Item C:\Windows\System32\forwarders\shell32.dll $destinationDir }