Last active
September 4, 2024 03:51
-
-
Save jcefoli/c79a2b6aaf189e531d3d44ef1bce707b to your computer and use it in GitHub Desktop.
PowerShell Build Script for mRemoteNG latest dev branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.REQUIREMENTS | |
- Visual Studio 2022 | |
- Wix Toolset 3.x | |
- .NET framework SDKs / core required by app | |
- Nuget | |
- git | |
#> | |
# Custom Variables | |
$gitDir = "C:\git\mRemoteNG" | |
$binDir = "$gitDir\mRemoteNG\bin\x64\Release" | |
$buildOutputDir = "C:\bin\mRemoteNG" | |
$msBuildBinary = "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\msbuild.exe" | |
$slnPath = "C:\Git\MremoteNG\mRemoteNG.sln" | |
$zipOutputFile = "C:\bin\mRemoteNG.zip" | |
$msBuildArgs = @" | |
/nologo /p:Configuration="Release";Platform=x64;UseSharedCompilation=false $slnPath | |
"@ | |
$robocopyArgs = @" | |
/MIR "$binDir" "$buildOutputDir" /XF "*.xml" /XF "mRemoteNG.settings" | |
"@ | |
Set-Location -Path "$gitDir" | |
#Build will fail without this for some dumb reason | |
$Env:DevEnvDir = (. ./Tools/find_vstool.ps1 devenv.exe).replace("devenv.exe","") | |
# Git the latest (will nuke any local changes) | |
$defaultBranch = $(git remote show origin | Select-String -Pattern 'HEAD branch' | ForEach-Object { $_ -replace '.*: ', '' }) | |
. git -C $gitDir\ fetch --all | |
. git -C $gitDir\ checkout $defaultBranch | |
. git -C $gitDir\ reset --hard origin/$defaultBranch | |
# Clean Up /bin/ directory | |
if (Test-Path $binDir) { Remove-Item -Path $binDir -Recurse -Force } | |
# Check for running process | |
$process = Get-Process | Where-Object {$_.name -eq "mRemoteNG"} | |
$i = 0 | |
while ($null -ne $process){ | |
Write-Output "[WARNING] mRemoteNG is running. Close to continue building..." | |
$i = $i + 1000 | |
$process = get-process | Where-Object {$_.name -eq "mRemoteNG"} | |
Start-Sleep -Milliseconds 1000 | |
} | |
# Restore nuget packages | |
. nuget restore $slnPath | |
# dotnet restore (sexier than nuget restore) | |
dotnet restore | |
# Run MSBuild | |
$process = Start-Process -FilePath $msBuildBinary -ArgumentList $msBuildArgs -Wait -NoNewWindow -PassThru | |
# Detect teh failz FTL | |
if ($process.ExitCode -ne 0) { | |
Write-Error "MSBuild failed with exit code $($process.ExitCode)" | |
Exit 69 | |
} | |
# Custom Check for compilation success | |
if (Test-Path "$binDir\mRemoteNG.exe") { | |
# I like to move it move it (actually, copy it) | |
Start-Process -FilePath "robocopy" -ArgumentList $robocopyArgs -Wait -WorkingDirectory $pwd -NoNewWindow | |
#Remove old zip file | |
if (Test-Path "$zipOutputFile" -ErrorAction SilentlyContinue) { | |
Remove-Item "$zipOutputFile" | |
} | |
#Zippy zip | |
Compress-Archive -Path "$binDir\*" -DestinationPath "$zipOutputFile" -Force | |
Write-Output "`n`nIt all worked! You're Done" | |
} else { | |
# executable doesn't exist | |
Write-Error "`n`nWomp womp! Build failed. Check logs!" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment