Allow Toolkit to work when ps1 is compiled to exe using Sapien PS Studio 2015

In order to get the Deploy-Application.ps1 working when compiled/build to exe using SAPIEN PowerShell Studio 2015 following changes are required:

in Deploy-Application.ps1:

  1. modify how the environment variable is declared. Currently it only works when ps1 file is launched not when compiled to exe
    suggested code to replace line 83 in version 3.6.4
    if ($hostinvocation -ne $null)
    [string]$scriptDirectory = Split-Path -Path $HostInvocation.MyCommand.Path -Parent
    [string]$scriptDirectory = Split-Path -Path $script:MyInvocation.MyCommand.Path -Parent

in AppDeployToolkitMain.ps1:

  1. the exe hangs at the end during an interactive install when made use of the Show-InstallationProgress function. This happens because the $global:ProgressRunSpace is still running.
    suggested code to be placed after line 6438 ($global:ProgressSyncHash.Clear()) in version 3.6.4

  2. the exe does not return the exitcode
    suggested code to replace line 854 in version 3.6.4
    If ($HostInvocation -ne $null)
    $script:ExitCode = $exitCode
    Exit $exitCode

Any tips are coverting 3.6.8?