A native macOS / windows / Linux database IDE built with Swift and AppKit. Connect to PostgreSQL, MySQL, SQLite, and Redis from a single app with a fast, keyboard-driven interface.
C++
# build-unpackaged.ps1
# ----------------------------------------------------------------------
# Build Gridex.vcxproj as an UNPACKAGED WinUI 3 app for Velopack.
#
# The default project config is packaged (MSIX, AppxPackage=true). This
# script DOES NOT mutate the vcxproj -- it only passes the unpackaged
# property overrides via /p: so the existing packaged build path is
# preserved untouched. Re-running the standard MSIX build still works.
#
# Output: E:\dev\be\vura\windows\x64\Release\Gridex\
# ----------------------------------------------------------------------
param(
[string]$Configuration = "Release",
[string]$Version = ""
)
$ErrorActionPreference = "Stop"
# Resolve the repo root from the script location: scripts -> windows -> repo
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..\..")
$proj = Join-Path $repoRoot "windows\Gridex\Gridex.vcxproj"
if (-not (Test-Path $proj)) {
throw "Gridex.vcxproj not found at: $proj"
}
# Stamp the version into GridexVersion.generated.h. The header is
# included unconditionally by GridexVersion.h, so MSBuild's incremental
# build can rely on the real file dependency in .tlog (a conditional
# __has_include would be invisible to the dependency scanner and leave
# stale SettingsPage.obj across runs). CI passes -Version from the tag;
# local dev runs fall through to "0.0.0-dev" which makes the About
# section obviously non-release.
$effectiveVersion = if ($Version -ne "") { $Version } else { "0.0.0-dev" }
$genHeader = Join-Path $repoRoot "windows\Gridex\GridexVersion.generated.h"
$genContent = @"
#pragma once
// AUTO-GENERATED by windows\scripts\build-unpackaged.ps1 -- do not edit.
// Defines GRIDEX_VERSION used by SettingsPage About section.
// CI workflow stamps the real tag version; local dev builds get "dev".
#define GRIDEX_VERSION L"$effectiveVersion"
"@
# Only rewrite when the content actually changes -- otherwise we bump
# the file's mtime on every run and force MSBuild to recompile
# SettingsPage.obj for no reason.
$existing = if (Test-Path $genHeader) { Get-Content $genHeader -Raw } else { "" }
if ($existing -ne "$genContent`r`n" -and $existing -ne $genContent) {
Set-Content -Path $genHeader -Value $genContent -Encoding ASCII
Write-Host "Stamped version $effectiveVersion -> $genHeader" -ForegroundColor Cyan
} else {
Write-Host "Version $effectiveVersion already stamped (skip rewrite)" -ForegroundColor DarkGray
}
# Locate VS install + MSBuild via vswhere -- works for any VS 2022+
# install layout without hardcoding a path. Falls back to PATH if
# vswhere absent.
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$vsDir = $null
$msbuild = $null
if (Test-Path $vswhere) {
$vsDir = & $vswhere -latest -property installationPath
$msbuild = & $vswhere -latest -requires Microsoft.Component.MSBuild `
-find "MSBuild\**\Bin\MSBuild.exe" | Select-Object -First 1
}
if (-not $msbuild) {
$cmd = Get-Command msbuild -ErrorAction SilentlyContinue
if ($cmd) { $msbuild = $cmd.Source }
}
if (-not $msbuild) {
throw "MSBuild.exe not found. Install VS 2022 Build Tools (Desktop C++ workload)."
}
Write-Host "MSBuild: $msbuild" -ForegroundColor Cyan
# Step 1: NuGet restore (packages.config project).
#
# Gridex.vcxproj still uses the legacy packages.config format (the
# ..\packages\<id>.<ver>\ layout). MSBuild's plain `/restore` flag only
# handles PackageReference projects; for packages.config we must pass
# RestorePackagesConfig=true (NuGet 5.x+). Without this, a clean
# checkout (e.g. fresh CI runner) fails with
# "The missing file is ..\packages\Microsoft.Web.WebView2.1.0.3179.45\
# build\native\Microsoft.Web.WebView2.targets."
& $msbuild $proj `
/t:Restore `
/p:RestorePackagesConfig=true `
/p:Configuration=$Configuration `
/p:Platform=x64
if ($LASTEXITCODE -ne 0) {
throw "MSBuild restore failed with exit code $LASTEXITCODE"
}
# Step 2: Build unpackaged.
#
# Property overrides:
# WindowsPackageType=None -> Build as unpackaged Win32 app
# WindowsAppSDKSelfContained=true -> Bundle WinAppSDK runtime DLLs side-by-side
# AppxPackage=false -> Skip MSIX packaging step
# GenerateAppxPackageOnBuild=false-> Belt-and-braces for AppxPackage flag
#
# Together these flip the project from MSIX to a self-contained Win32 layout
# that Velopack can pack directly with `vpk pack --packDir`.
& $msbuild $proj `
/p:Configuration=$Configuration `
/p:Platform=x64 `
/p:WindowsPackageType=None `
/p:WindowsAppSDKSelfContained=true `
/p:AppxPackage=false `
/p:GenerateAppxPackageOnBuild=false `
/m
if ($LASTEXITCODE -ne 0) {
throw "MSBuild failed with exit code $LASTEXITCODE"
}
#
# MSBuild emits the full unpackaged output (including all WinAppSDK runtime
# DLLs) to the PROJECT-nested path, not the solution-level $(SolutionDir)\x64
# path. The solution-level path may also contain stale files from an earlier
# packaged build -- ignore it.
#
$outDir = Join-Path $repoRoot "windows\Gridex\x64\$Configuration\Gridex"
if (-not (Test-Path $outDir)) {
throw "Build succeeded but output dir missing: $outDir"
}
# --- Bundle VC++ Redistributable runtime DLLs ---------------------------
#
# Gridex.exe imports MSVCP140.dll / VCRUNTIME140.dll / VCRUNTIME140_1.dll
# from the VC++ 2015-2022 Redistributable. These are NOT bundled by WinUI
# 3 self-contained build -- they ship with the system via the VC Redist
# installer. Fresh Windows installs (or stripped images) will crash
# Gridex.exe at startup with "MSVCP140.dll not found" if VC Redist is
# missing (~5-15% of machines).
#
# Fix: copy all CRT DLLs from the VS VC\Redist\MSVC\<ver>\x64\Microsoft.VC*.CRT
# folder into the build output. Microsoft's Visual C++ redistributable
# license explicitly allows this. Adds ~2 MB to Setup.exe.
#
if ($vsDir) {
$vcRedistRoot = Join-Path $vsDir 'VC\Redist\MSVC'
if (Test-Path $vcRedistRoot) {
# Pick the highest numeric version directory (e.g. 14.50.35710)
$crtVersionDir = Get-ChildItem $vcRedistRoot -Directory |
Where-Object { $_.Name -match '^\d+\.\d+\.\d+' } |
Sort-Object { [Version]$_.Name } -Descending |
Select-Object -First 1
if ($crtVersionDir) {
$crtDir = Get-ChildItem (Join-Path $crtVersionDir.FullName 'x64') `
-Directory -Filter 'Microsoft.VC*.CRT' -ErrorAction SilentlyContinue |
Select-Object -First 1
if ($crtDir) {
$dllCount = 0
Get-ChildItem (Join-Path $crtDir.FullName '*.dll') | ForEach-Object {
Copy-Item $_.FullName -Destination $outDir -Force
$dllCount++
}
Write-Host "Copied $dllCount VC runtime DLL(s) from $($crtDir.Name)" -ForegroundColor Cyan
} else {
Write-Warning "VC CRT folder not found under $($crtVersionDir.FullName)\x64 -- users will need VC++ Redist installed"
}
} else {
Write-Warning "No versioned VC CRT redist folder found in $vcRedistRoot"
}
} else {
Write-Warning "VC Redist root missing: $vcRedistRoot"
}
}
# -----------------------------------------------------------------------
# --- Bundle vcpkg runtime DLLs -----------------------------------------
#
# Gridex.exe dynamically links libpq, libmariadb, sqlite3, libssl,
# libcrypto, hiredis (+ their transitive deps like zlib1, brotli*,
# lz4) from vcpkg's x64-windows triplet. MSBuild's vcpkg integration
# is supposed to run applocal.ps1 post-link to copy these DLLs into
# the output folder, but that step is flaky on CI runners -- the
# windows-2022 GitHub runner prints "pwsh.exe exited with code 9009"
# because PowerShell Core isn't on PATH, and the step silently does
# nothing. Without the DLLs, Setup.exe installs fine but the installed
# Gridex.exe crashes at startup with "libpq.dll not found" et al.
#
# Fix: copy the entire vcpkg bin/*.dll set explicitly. A few DLLs are
# transitive deps we don't directly reference (legacy.dll, libecpg*,
# libpgtypes.dll) but copying the whole set is safer than maintaining
# a curated list that drifts when vcpkg updates package layouts.
# Skip .pdb files to keep Setup.exe small.
#
$vcpkgBin = 'C:\vcpkg\installed\x64-windows\bin'
if (Test-Path $vcpkgBin) {
$dllCount = 0
Get-ChildItem (Join-Path $vcpkgBin '*.dll') | ForEach-Object {
Copy-Item $_.FullName -Destination $outDir -Force
$dllCount++
}
Write-Host "Copied $dllCount vcpkg runtime DLL(s) from $vcpkgBin" -ForegroundColor Cyan
} else {
Write-Warning "vcpkg bin missing: $vcpkgBin -- Setup.exe will be missing libpq/libmariadb/etc."
}
# --- Bundle libmariadb auth plugins ------------------------------------
#
# libmariadb ships each auth plugin as a separate DLL (caching_sha2_password,
# client_ed25519, sha256_password, dialog, mysql_clear_password). The
# built-in mysql_native_password auth works without these — everything
# else requires the matching DLL to be loadable from MYSQL_PLUGIN_DIR.
# vcpkg installs them under plugins/libmariadb/ on the build machine,
# but that path obviously doesn't exist on customer machines. Copy them
# next to Gridex.exe so the code in MySQLAdapter.cpp can point
# MYSQL_PLUGIN_DIR at <app>/plugins/mariadb/ and real MySQL 8 servers
# (caching_sha2_password by default) will auth without requiring the
# admin to --default-authentication-plugin=mysql_native_password.
#
$mariadbPluginSrc = 'C:\vcpkg\installed\x64-windows\plugins\libmariadb'
$mariadbPluginDst = Join-Path $outDir 'plugins\mariadb'
if (Test-Path $mariadbPluginSrc) {
New-Item -ItemType Directory -Force -Path $mariadbPluginDst | Out-Null
$pluginCount = 0
Get-ChildItem (Join-Path $mariadbPluginSrc '*.dll') | ForEach-Object {
Copy-Item $_.FullName -Destination $mariadbPluginDst -Force
$pluginCount++
}
Write-Host "Copied $pluginCount libmariadb auth plugin(s) to $mariadbPluginDst" -ForegroundColor Cyan
} else {
Write-Warning "libmariadb plugin dir missing: $mariadbPluginSrc -- MySQL 8 caching_sha2_password auth will fail at runtime."
}
# -----------------------------------------------------------------------
# --- Bundle Microsoft Edge WebView2 Runtime bootstrap ------------------
#
# Gridex uses a WebView2 element in the ER Diagram view. Windows 11 and
# recently-updated Windows 10 ship with the WebView2 Runtime via Edge
# automatically, but fresh/stripped Windows installs may lack it. The
# C++ code in App.xaml.cpp (EnsureWebView2Runtime) silently runs this
# bootstrap installer on first launch if the runtime is missing.
#
# The bootstrap is a ~2 MB stub that downloads the real runtime from
# Microsoft's CDN on demand. We cache it in windows\vendor\webview2\
# to avoid re-downloading on every build.
#
$vendorDir = Join-Path $repoRoot "windows\vendor\webview2"
$bootstrapName = "MicrosoftEdgeWebView2Setup.exe"
$bootstrapPath = Join-Path $vendorDir $bootstrapName
$bootstrapUrl = "https://go.microsoft.com/fwlink/p/?LinkId=2124703"
if (-not (Test-Path $bootstrapPath)) {
Write-Host "Downloading WebView2 bootstrap installer..." -ForegroundColor Cyan
New-Item -ItemType Directory -Force -Path $vendorDir | Out-Null
try {
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $bootstrapUrl -OutFile $bootstrapPath -UseBasicParsing
$ProgressPreference = 'Continue'
Write-Host " cached at $bootstrapPath ($([math]::Round((Get-Item $bootstrapPath).Length/1KB,1)) KB)" -ForegroundColor Green
} catch {
Write-Warning "Failed to download WebView2 bootstrap: $_"
}
}
if (Test-Path $bootstrapPath) {
Copy-Item $bootstrapPath -Destination $outDir -Force
Write-Host "Bundled WebView2 bootstrap: $bootstrapName" -ForegroundColor Cyan
}
# -----------------------------------------------------------------------
$fileCount = (Get-ChildItem $outDir -File).Count
Write-Host "Unpackaged build output: $outDir ($fileCount files)" -ForegroundColor Green