diff --git a/.vscode/launch.json b/.vscode/launch.json index 9c7be0a5..ade9bd7b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,5 +1,12 @@ { "configurations": [ + { + "name": "PowerShell Launch Current File", + "type": "PowerShell", + "request": "launch", + "script": "${file}", + "cwd": "${cwd}" + }, { "type": "node", "request": "launch", diff --git a/dist/platforms/windows/build.ps1 b/dist/platforms/windows/build.ps1 index ba674445..1dc07bcf 100644 --- a/dist/platforms/windows/build.ps1 +++ b/dist/platforms/windows/build.ps1 @@ -131,27 +131,44 @@ Write-Output "" # If $Env:CUSTOM_PARAMETERS contains spaces and is passed directly on the command line to Unity, powershell will wrap it # in double quotes. To avoid this, parse $Env:CUSTOM_PARAMETERS into an array, while respecting any quotations within the string. -$_, $customParametersArray = Invoke-Expression('Write-Output -- "" ' + $Env:CUSTOM_PARAMETERS) +$_, $customParametersArray = Invoke-Expression('Write-Output -- "" ' + $Env:CUSTOM_PARAMETERS) | ForEach-Object { $_.ToString() } -& "C:\Program Files\Unity\Hub\Editor\$Env:UNITY_VERSION\Editor\Unity.exe" -quit -batchmode -nographics ` - -projectPath $Env:UNITY_PROJECT_PATH ` - -executeMethod $Env:BUILD_METHOD ` - -buildTarget $Env:BUILD_TARGET ` - -customBuildTarget $Env:BUILD_TARGET ` - -customBuildPath $Env:CUSTOM_BUILD_PATH ` - -buildVersion $Env:VERSION ` - -androidVersionCode $Env:ANDROID_VERSION_CODE ` - -androidKeystorePass $Env:ANDROID_KEYSTORE_PASS ` - -androidKeyaliasName $Env:ANDROID_KEYALIAS_NAME ` - -androidKeyaliasPass $Env:ANDROID_KEYALIAS_PASS ` - -androidTargetSdkVersion $Env:ANDROID_TARGET_SDK_VERSION ` - -androidExportType $Env:ANDROID_EXPORT_TYPE ` - -androidSymbolType $Env:ANDROID_SYMBOL_TYPE ` - $customParametersArray ` - -logfile | Out-Host +$process = Start-Process -FilePath "C:\Program Files\Unity\Hub\Editor\$Env:UNITY_VERSION\Editor\Unity.exe" ` + -ArgumentList @("-quit", + "-batchmode", + "-nographics", + "-projectPath", $Env:UNITY_PROJECT_PATH, + "-executeMethod", $Env:BUILD_METHOD, + "-buildTarget", $Env:BUILD_TARGET, + "-customBuildTarget", $Env:BUILD_TARGET, + "-customBuildPath", $Env:CUSTOM_BUILD_PATH, + "-buildVersion", $Env:VERSION, + "-androidVersionCode", $Env:ANDROID_VERSION_CODE, + "-androidKeystorePass", $Env:ANDROID_KEYSTORE_PASS, + "-androidKeyaliasName", $Env:ANDROID_KEYALIAS_NAME, + "-androidKeyaliasPass", $Env:ANDROID_KEYALIAS_PASS, + "-androidTargetSdkVersion", $Env:ANDROID_TARGET_SDK_VERSION, + "-androidExportType", $Env:ANDROID_EXPORT_TYPE, + "-androidSymbolType", $Env:ANDROID_SYMBOL_TYPE, + "-logfile", "-", "./build.log", + "-silent-crashes" + ) + $customParametersArray ` + -NoNewWindow ` + -PassThru + +# This ensures that the Unity Editor properly exits as it can hang on Windows +while (!$process.StandardOutput.EndOfStream) { + +if ($process.HasExited) { + Write-Host "`nExecute Method Ended`n" + exit 0; +} + +Start-Sleep -Seconds 1 +} # Catch exit code -$Env:BUILD_EXIT_CODE=$LastExitCode +$Env:BUILD_EXIT_CODE=$process.ExitCode # Display results if ($Env:BUILD_EXIT_CODE -eq 0) diff --git a/dist/platforms/windows/entrypoint.ps1 b/dist/platforms/windows/entrypoint.ps1 index ba207b88..e07a3575 100644 --- a/dist/platforms/windows/entrypoint.ps1 +++ b/dist/platforms/windows/entrypoint.ps1 @@ -1,37 +1,21 @@ -Get-Process - # Import any necessary registry keys, ie: location of windows 10 sdk # No guarantee that there will be any necessary registry keys, ie: tvOS -Get-ChildItem -Path c:\regkeys -File | Foreach {reg import $_.fullname} -Start-Sleep 3 -Get-Process +Get-ChildItem -Path c:\regkeys -File | ForEach-Object {reg import $_.fullname} # Register the Visual Studio installation so Unity can find it regsvr32 C:\ProgramData\Microsoft\VisualStudio\Setup\x64\Microsoft.VisualStudio.Setup.Configuration.Native.dll -Start-Sleep 3 -Get-Process # Setup Git Credentials & "c:\steps\set_gitcredential.ps1" -Start-Sleep 3 -Get-Process # Activate Unity & "c:\steps\activate.ps1" -Start-Sleep 3 -Get-Process # Build the project & "c:\steps\build.ps1" -Start-Sleep 3 -Get-Process # Free the seat for the activated license & "c:\steps\return_license.ps1" -Start-Sleep 3 -Get-Process # Kill the regsvr process Get-Process -Name regsvr32 | ForEach-Object { Stop-Process -Id $_.Id -Force } -Start-Sleep 3 -Get-Process