$DelphiDir = "C:\Program Files (x86)\Embarcadero\Studio\22.0"
$BuildPlatform = "
Win32"
$BuildConfig = "Debug"
$ProjectDir = "C:\Irgendwo"
$ProjectFile = "C:\Irgendwo\MyTest.dproj"
## INIT
$PInfo = New-Object System.Diagnostics.ProcessStartInfo
$PInfo.WorkingDirectory = $ProjectDir
$PInfo.FileName = "cmd.exe" # oder $Env.ComSpec
#$PInfo.Arguments = "/s", "/c", "call `"$DelphiDir\bin\rsvars.bat`" `& MSBuild.exe /nologo /target:Build /property:Platform=$BuildPlatform /property:Config=$BuildConfig `"$ProjectFile`""
#$PInfo.Arguments = "/s", "/c", "call `"$DelphiDir\bin\rsvars.bat`" `& echo MSBuild.exe /nologo /target:Build /property:Platform=$BuildPlatform /property:Config=$BuildConfig `"$ProjectFile`" `& set"
#$PInfo.Arguments = "/c", "MSBuild.exe /nologo /target:Build /property:Platform=$BuildPlatform /property:Config=$BuildConfig `"$ProjectFile`""
$PInfo.Arguments = "/c", "set"
$PInfo.RedirectStandardError = $true
$PInfo.RedirectStandardOutput = $true
$PInfo.UseShellExecute = $false
## LOAD rsvars.bat
if ($true) { #if ($PInfo.Arguments -NotContains "rsvars") {
foreach ($Line in (Get-Content "C:\Program Files (x86)\Embarcadero\Studio\22.0\bin\rsvars.bat")) {
if ($Line.Trim() -ne "") {
$Key = $Line.Split('=')[0].TrimStart("@SET").Trim()
$Value = ($Line.Split('=')[1] + "").Trim()
foreach ($Match in (Select-String "%([a-z0-9_]+)%" -input $Value -AllMatches).Matches) {
$Value2 = ($PInfo.EnvironmentVariables[$Match.Value.Trim("%")] + "").Trim()
#if ( ($Value2 -ne $null) -And ($Value2 -ne "") ) {
$Value = $Value.Replace($Match.Value, $Value2)
#}
}
Write-Host "set `"$Key`" = `"$Value`""
$PInfo.EnvironmentVariables[$Key] = $Value
}
}
}
## EXECUTE
$Process = New-Object System.Diagnostics.Process
$Process.StartInfo = $pinfo
$Process.Start() | Out-Null
#$Process.WaitForExit()
if ($Process.WaitForExit(10 * 1000) -ne $true) {
$Process.Kill()
#throw "TIMEOUT"
Write-Host "{TIMEOUT}"
}
$StdOut = $Process.StandardOutput.ReadToEnd()
$StdErr = $Process.StandardError.ReadToEnd()
## LOG
Write-Host "ExitCode:", $Process.ExitCode
Write-Host "StdOut:`n$StdOut"
Write-Host "StdErr:`n$StdErr"