<# build.ps1 - Standalone, from-scratch build script for Logbert. Logbert is a .NET Framework 4.8 WinForms desktop application (log viewer for log4net / log4j / NLog / syslog). The solution contains three managed projects that build with MSBuild: - Couchcoding.Logbert.Theme (class library) - Couchcoding.Logbert.Gui (class library) - Logbert (WinExe - the GUI application) All third-party dependencies (MoonSharp, ScintillaNET, WeifenLuo docking) ship as pre-built DLLs checked into src\Logbert\Libraries, so there is no NuGet / package restore step. The only build requirements are: - MSBuild (Visual Studio Build Tools 2022, MSVC/.NET desktop workload) - .NET Framework 4.8 targeting pack Both are part of the "Visual Studio Build Tools 2022 with .NET desktop workload" that is pre-installed on the build machine. If MSBuild cannot be located the script will attempt to install the Build Tools via Chocolatey. The script builds Release|x64 and copies the resulting binaries to the install directory. #> [CmdletBinding()] param( [string]$Configuration = 'Release', [string]$Platform = 'x64' ) $ErrorActionPreference = 'Stop' # RB unified-0827: build_result.json is portable on OSS; materialize its path for this VM run. $__rbBuildResultPath = Join-Path $PSScriptRoot 'build_result.json' if (Test-Path $__rbBuildResultPath) { $__rbBuildResult = Get-Content $__rbBuildResultPath -Raw -Encoding UTF8 | ConvertFrom-Json if ($__rbBuildResult.executable -and -not [System.IO.Path]::IsPathRooted([string]$__rbBuildResult.executable)) { $__rbBuildResult.executable = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot ([string]$__rbBuildResult.executable))) $__rbBuildResult | ConvertTo-Json -Depth 10 | Set-Content $__rbBuildResultPath -Encoding UTF8 } } Set-StrictMode -Version Latest # --------------------------------------------------------------------------- # Paths # --------------------------------------------------------------------------- $RepoRoot = (Join-Path (Split-Path $PSScriptRoot -Parent) 'repo') $SrcDir = Join-Path $RepoRoot 'src' $ProjectFile = Join-Path $SrcDir 'Logbert\Logbert.csproj' $InstallDir = (Join-Path (Split-Path $PSScriptRoot -Parent) 'install') Write-Output "=== Logbert build starting ($Configuration|$Platform) ===" Write-Output "Repo root : $RepoRoot" Write-Output "Project : $ProjectFile" Write-Output "Install to : $InstallDir" if (-not (Test-Path $ProjectFile)) { throw "Project file not found: $ProjectFile" } # --------------------------------------------------------------------------- # Locate MSBuild (via vswhere). Install VS Build Tools if it is missing. # --------------------------------------------------------------------------- function Find-MSBuild { $vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe' if (Test-Path $vswhere) { $msb = & $vswhere -latest -products * ` -requires Microsoft.Component.MSBuild ` -find 'MSBuild\**\Bin\MSBuild.exe' | Select-Object -First 1 if ($msb -and (Test-Path $msb)) { return $msb } } # Fallback: probe well-known install locations. $candidates = @( 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe', 'C:\Program Files\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe', 'C:\Program Files (x86)\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe', 'C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe', 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe', 'C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe' ) foreach ($c in $candidates) { if (Test-Path $c) { return $c } } return $null } $msbuild = Find-MSBuild if (-not $msbuild) { Write-Output "MSBuild not found - installing Visual Studio Build Tools 2022 via Chocolatey ..." choco install -y visualstudio2022buildtools ` --package-parameters "--add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools --add Microsoft.VisualStudio.Workload.NetCoreBuildTools --includeRecommended --quiet --norestart" choco install -y netfx-4.8-devpack $msbuild = Find-MSBuild if (-not $msbuild) { throw "MSBuild could not be located even after installing the Build Tools." } } Write-Output "Using MSBuild: $msbuild" & $msbuild -version # --------------------------------------------------------------------------- # Build (Rebuild = clean + build) the GUI project. Project references pull in # the Gui and Theme class libraries automatically. # --------------------------------------------------------------------------- Write-Output "=== Building ===" & $msbuild $ProjectFile ` "/t:Rebuild" ` "/p:Configuration=$Configuration" ` "/p:Platform=$Platform" ` "/m" ` "/v:minimal" ` "/nologo" if ($LASTEXITCODE -ne 0) { throw "MSBuild failed with exit code $LASTEXITCODE" } # --------------------------------------------------------------------------- # Install: copy the build output to the install directory. # --------------------------------------------------------------------------- $OutputDir = Join-Path $SrcDir "Logbert\bin\$Platform\$Configuration" if (-not (Test-Path (Join-Path $OutputDir 'Logbert.exe'))) { throw "Build output not found at: $OutputDir\Logbert.exe" } Write-Output "=== Installing to $InstallDir ===" New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null # Clean any stale contents so the install directory always mirrors the build. Get-ChildItem -Path $InstallDir -Force -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue Copy-Item -Path (Join-Path $OutputDir '*') -Destination $InstallDir -Recurse -Force # --------------------------------------------------------------------------- # Harden the installed configuration for automated (re)launching. # # Logbert enforces a single running instance via a machine-global named pipe # (see Program.cs / FrmMainAllowOnlyOneInstance). When the app is relaunched # while a previous instance is still alive, the new process detects the pipe, # hands off to the existing instance and exits immediately. That breaks a test # harness that starts the app multiple times. Disable the single-instance # guard in the installed config so every launch spins up its own GUI. # Also suppress the "check for update on startup" network call and the welcome # page so the app comes up clean and self-contained. # --------------------------------------------------------------------------- $cfgPath = Join-Path $InstallDir 'Logbert.exe.config' if (Test-Path $cfgPath) { Write-Output "=== Patching $cfgPath (disable single-instance guard) ===" [xml]$cfg = Get-Content -LiteralPath $cfgPath $overrides = @{ 'FrmMainAllowOnlyOneInstance' = 'False' 'FrmMainCheckForUpdateOnStartup' = 'False' } foreach ($node in $cfg.SelectNodes('//setting')) { if ($overrides.ContainsKey($node.name)) { $node.value = $overrides[$node.name] } } $cfg.Save($cfgPath) } $exePath = Join-Path $InstallDir 'Logbert.exe' if (-not (Test-Path $exePath)) { throw "Install failed - $exePath does not exist." } Write-Output "=== Build complete ===" Write-Output "Executable: $exePath" Get-ChildItem $InstallDir | Select-Object Name, Length | Format-Table -AutoSize