diff --git a/Tools/copy_puttyng.ps1 b/Tools/copy_puttyng.ps1 new file mode 100644 index 00000000..21dc6180 --- /dev/null +++ b/Tools/copy_puttyng.ps1 @@ -0,0 +1,15 @@ +param ( + [string] + [Parameter(Mandatory=$true)] + $SolutionDir, + + [string] + [Parameter(Mandatory=$true)] + $TargetDir +) + +Write-Output "===== Beginning $($PSCmdlet.MyInvocation.MyCommand) =====" +Write-Output "Copying PUTTYNG to correct directory" +Copy-Item -Path (Join-Path -Path $SolutionDir -ChildPath "mRemoteV1\Resources\PuTTYNG.exe") -Destination $TargetDir -Force + +Write-Output "" \ No newline at end of file diff --git a/Tools/move_help_files.ps1 b/Tools/move_help_files.ps1 new file mode 100644 index 00000000..dc63866f --- /dev/null +++ b/Tools/move_help_files.ps1 @@ -0,0 +1,23 @@ +param ( + [string] + [Parameter(Mandatory=$true)] + $TargetDir +) + +Write-Output "===== Beginning $($PSCmdlet.MyInvocation.MyCommand) =====" + +$path_HelpFilesDir = Join-Path -Path $TargetDir -ChildPath "Help" + +Write-Output "Moving Help files to correct directory" + +# Remove stale Help files, if they exist +if (Test-Path -Path $path_HelpFilesDir) { + Remove-Item -Path $path_HelpFilesDir -Recurse -Force +} + +# Move Help files +Move-Item -Path (Join-Path -Path $TargetDir -ChildPath "Resources\Help") -Destination $path_HelpFilesDir -Force +Start-Sleep -Seconds 2 +Remove-Item -Path (Join-Path -Path $TargetDir -ChildPath "Resources") -Recurse -Force + +Write-Output "" \ No newline at end of file diff --git a/Tools/postbuild_mremotev1.ps1 b/Tools/postbuild_mremotev1.ps1 index 2a7dc64c..8748e7a2 100644 --- a/Tools/postbuild_mremotev1.ps1 +++ b/Tools/postbuild_mremotev1.ps1 @@ -16,57 +16,16 @@ param ( $ConfigurationName ) -$certificatePath = "C:\mRemoteNG_code_signing_cert.pfx" -$path_signFilesScript = Join-Path -Path $SolutionDir -ChildPath "Tools\signfiles.ps1" -$path_packageZipScript = Join-Path -Path $SolutionDir -ChildPath "Tools\build-relport.cmd" -$path_HelpFilesDir = Join-Path -Path $TargetDir -ChildPath "Help" -$path_outputExe = Join-Path -Path $TargetDir -ChildPath $TargetFileName -$path_editBin = @((Resolve-Path -Path "C:\Program Files*\Microsoft Visual Studio*\VC\bin\editbin.exe").Path)[0] +Write-Output "+=================================================================+" +Write-Output "| Beginning mRemoteV1 Post Build |" +Write-Output "+=================================================================+" +Write-Output ([pscustomobject]$PSBoundParameters) | Format-Table -AutoSize -Wrap - -# Copy PuTTYNG -Write-Host "Copy PUTTYNG to correct directory" -ForegroundColor Green -Copy-Item -Path (Join-Path -Path $SolutionDir -ChildPath "mRemoteV1\Resources\PuTTYNG.exe") -Destination $TargetDir -Force - - - -# Move Help files -Write-Host "Move Help files to correct directory" -ForegroundColor Green -if (Test-Path -Path $path_HelpFilesDir) { - Remove-Item -Path $path_HelpFilesDir -Recurse -Force -} -Move-Item -Path (Join-Path -Path $TargetDir -ChildPath "Resources\Help") -Destination $path_HelpFilesDir -Force -Start-Sleep -Seconds 2 -Remove-Item -Path (Join-Path -Path $TargetDir -ChildPath "Resources") -Recurse -Force - - - -# Set LargeAddressAware -Write-Host "Set LargeAddressAware on binary" -ForegroundColor Green -& $path_editBin "/largeaddressaware $path_outputExe" - - - -# Remove unnecessary files from Release versions -if (($ConfigurationName -match "Release") -and (Test-Path -Path $certificatePath -PathType Leaf)) { - Write-Host "Removing unnecessary files from Release versions" -ForegroundColor Green - Remove-Item -Path (Join-Path -Path $TargetDir -ChildPath "app.publish") -Recurse -Force - Remove-Item -Path $TargetDir -Include @( - "*.pdb", - "*.publish", - "*.xml", - "*.backup", - "*.log", - "*vshost*", - "*.tmp" - ) -} - - - -# Package Zip -if ($ConfigurationName -match "Release" -and $ConfigurationName -match "Portable") { - Write-Host "Package ZIP Release Portable" -ForegroundColor Green - & $path_packageZipScript -} \ No newline at end of file +& "$PSScriptRoot\copy_puttyng.ps1" -SolutionDir $SolutionDir -TargetDir $TargetDir +& "$PSScriptRoot\move_help_files.ps1" -TargetDir $TargetDir +& "$PSScriptRoot\set_LargeAddressAware.ps1" -TargetDir $TargetDir -TargetFileName $TargetFileName +& "$PSScriptRoot\tidy_files_for_release.ps1" -TargetDir $TargetDir -ConfigurationName $ConfigurationName +& "$PSScriptRoot\sign_binaries.ps1" -SolutionDir $SolutionDir -TargetDir $TargetDir -ConfigurationName $ConfigurationName +& "$PSScriptRoot\verify_binary_signatures.ps1" -TargetDir $TargetDir -ConfigurationName $ConfigurationName +& "$PSScriptRoot\zip_portable_files.ps1" -SolutionDir $SolutionDir -TargetDir $TargetDir -ConfigurationName $ConfigurationName \ No newline at end of file diff --git a/Tools/set_LargeAddressAware.ps1 b/Tools/set_LargeAddressAware.ps1 new file mode 100644 index 00000000..7cddeb6b --- /dev/null +++ b/Tools/set_LargeAddressAware.ps1 @@ -0,0 +1,21 @@ +param ( + [string] + [Parameter(Mandatory=$true)] + $TargetDir, + + [string] + [Parameter(Mandatory=$true)] + $TargetFileName +) + +Write-Output "===== Beginning $($PSCmdlet.MyInvocation.MyCommand) =====" + +$path_editBin = @((Resolve-Path -Path "C:\Program Files*\Microsoft Visual Studio*\VC\bin\editbin.exe").Path)[0] +$path_outputExe = Join-Path -Path $TargetDir -ChildPath $TargetFileName + + +# Set LargeAddressAware +Write-Output "Setting LargeAddressAware on binary" +& $path_editBin "/NOLOGO /largeaddressaware $path_outputExe" + +Write-Output "" \ No newline at end of file diff --git a/Tools/sign_binaries.ps1 b/Tools/sign_binaries.ps1 new file mode 100644 index 00000000..9a9e3a5b --- /dev/null +++ b/Tools/sign_binaries.ps1 @@ -0,0 +1,33 @@ +param ( + [string] + [Parameter(Mandatory=$true)] + $SolutionDir, + + [string] + [Parameter(Mandatory=$true)] + $TargetDir, + + [string] + [Parameter(Mandatory=$true)] + $ConfigurationName +) + +Write-Output "===== Beginning $($PSCmdlet.MyInvocation.MyCommand) =====" + +$certificatePath = "C:\mRemoteNG_code_signing_cert.pfx" +$path_signFilesScript = Join-Path -Path $SolutionDir -ChildPath "Tools\signfiles.ps1" + + +# Sign MSI if we are building a release version and the certificate is available +if ($ConfigurationName -match "Release") { + if (Test-Path -Path $certificatePath -PathType Leaf) { + Write-Output "Signing Binaries" + powershell.exe -ExecutionPolicy Bypass -File $path_signFilesScript $TargetDir + } else { + Write-Output "Certificate is not present - we won't sign files." + } +} else { + Write-Output "This is not a release build - we won't sign files." +} + +Write-Output "" \ No newline at end of file diff --git a/Tools/tidy_files_for_release.ps1 b/Tools/tidy_files_for_release.ps1 new file mode 100644 index 00000000..e57b3377 --- /dev/null +++ b/Tools/tidy_files_for_release.ps1 @@ -0,0 +1,31 @@ +param ( + [string] + [Parameter(Mandatory=$true)] + $TargetDir, + + [string] + [Parameter(Mandatory=$true)] + $ConfigurationName +) + +Write-Output "===== Beginning $($PSCmdlet.MyInvocation.MyCommand) =====" + +# Remove unnecessary files from Release versions +if ($ConfigurationName -match "Release") { + Write-Output "Removing unnecessary files from Release versions" + Remove-Item -Path (Join-Path -Path $TargetDir -ChildPath "app.publish") -Recurse -Force + Remove-Item -Path $TargetDir -Recurse -Include @( + "*.pdb", + "*.publish", + "*.xml", + "*.backup", + "*.log", + "*vshost*", + "*.tmp" + ) +} +else { + Write-Output "We will not remove anything - this is not a release build." +} + +Write-Output "" \ No newline at end of file diff --git a/Tools/verify_binary_signatures.ps1 b/Tools/verify_binary_signatures.ps1 new file mode 100644 index 00000000..08f8fd02 --- /dev/null +++ b/Tools/verify_binary_signatures.ps1 @@ -0,0 +1,36 @@ +param ( + [string] + [Parameter(Mandatory=$true)] + $TargetDir, + + [string] + [Parameter(Mandatory=$true)] + $ConfigurationName +) + +Write-Output "===== Beginning $($PSCmdlet.MyInvocation.MyCommand) =====" + +# Sign MSI if we are building a release version and the certificate is available +if ($ConfigurationName -match "Release") { + Write-Output "Verifying signature of binaries" + Write-Output "Getting files from path: $TargetDir" + $signableFiles = Get-ChildItem -Path $TargetDir -Recurse | ?{$_.Extension -match "dll|exe|msi"} + Write-Output "Signable files count: $($signableFiles.Count)" + $badSignatureFound = $false + foreach ($file in $signableFiles) { + $signature = Get-AuthenticodeSignature -FilePath $file.FullName + if ($signature.Status -ne "Valid") { + Write-Error "File $($file.FullName) does not have a valid signature." + $badSignatureFound = $true + } + } + if ($badSignatureFound) { + Write-Output "One or more files were improperly signed." + } else { + Write-Output "All files have valid signatures." + } +} else { + Write-Output "This is not a release build - we won't verify file signatures." +} + +Write-Output "" \ No newline at end of file diff --git a/Tools/zip_portable_files.ps1 b/Tools/zip_portable_files.ps1 new file mode 100644 index 00000000..97ddeebc --- /dev/null +++ b/Tools/zip_portable_files.ps1 @@ -0,0 +1,28 @@ +param ( + [string] + [Parameter(Mandatory=$true)] + $SolutionDir, + + [string] + [Parameter(Mandatory=$true)] + $TargetDir, + + [string] + [Parameter(Mandatory=$true)] + $ConfigurationName +) + +Write-Output "===== Beginning $($PSCmdlet.MyInvocation.MyCommand) =====" +$path_packageZipScript = Join-Path -Path $SolutionDir -ChildPath "Tools\build-relport.cmd" + + +# Package Zip +if ($ConfigurationName -match "Release" -and $ConfigurationName -match "Portable") { + Write-Output "Packaging Release Portable ZIP" + & $path_packageZipScript +} +else { + Write-Output "We will not zip anything - this isnt a portable release build." +} + +Write-Output "" \ No newline at end of file diff --git a/mRemoteV1/mRemoteV1.csproj b/mRemoteV1/mRemoteV1.csproj index fb3569c3..58fb5534 100644 --- a/mRemoteV1/mRemoteV1.csproj +++ b/mRemoteV1/mRemoteV1.csproj @@ -1247,44 +1247,17 @@ - powershell -noprofile -command "sleep 2" -call "$(DevEnvDir)..\tools\vsvars32.bat" -set /p buildenv=<buildenv.tmp - -echo Copy PUTTYNG to correct directory -copy /Y "$(SolutionDir)mRemoteV1\Resources\PuTTYNG.exe" .\ - -echo Move Help files to correct directory -IF EXIST Help ( - del /s /q Help >NUL - rmdir /s /q Help >NUL -) -move /Y Resources\Help .\ + :: When passing paths to powershell scripts, check if the path ends with a backslash "\" +:: If it does, then the backslash may be interpreted as an escape character. Add another backslash to cancel the first one. powershell -noprofile -command "sleep 2" -rmdir /s /q Resources >NUL +set /p buildenv=<buildenv.tmp +set solutionDir=$(SolutionDir)\ +set targetDir=%25cd%25 +set psScriptsDir=$(SolutionDir)Tools -echo Set LargeAddressAware on binary -editbin /largeaddressaware mRemoteNG.exe - - -IF EXIST C:\mRemoteNG_code_signing_cert.pfx ( - echo Signing binaries - IF %25buildenv: Portable=%25==Release ( - powershell "&""$(SolutionDir)Tools\signfiles.ps1""" '%25cd%25' - ) -) - -IF %25buildenv: Portable=%25==Release ( - echo Remove unnecessary files from Release versions - rmdir /s /q app.publish - del /q *.pdb *.publish *.xml *.backup *.log *vshost* *.tmp -) - -IF %25buildenv: =%25==ReleasePortable ( - echo Package ZIP Release Portable - "$(SolutionDir)Tools\build-relport.cmd" -) +:: Call the post build powershell script +powershell.exe -ExecutionPolicy Bypass -File "%25psScriptsDir%25\postbuild_mremotev1.ps1" -SolutionDir "%25solutionDir%25" -TargetDir "%25targetDir%25" -TargetFileName "mRemoteNG.exe" -ConfigurationName "%25buildenv%25" true