From 37309f30e1a74a260e4ca0957514404b7ae3f9d3 Mon Sep 17 00:00:00 2001 From: Amal Graafstra Date: Thu, 6 Nov 2025 23:21:14 -0800 Subject: [PATCH] Add release build configuration and MSI installer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Configure self-contained, single-file release build - Add version and company metadata to project - Fix Assembly.Location for single-file compatibility (use AppContext.BaseDirectory) - Add Resources folder copy to publish output - Create WiX installer project with Product.wxs - Configure auto-start via HKCU Run registry key - Add build-release.ps1 PowerShell script for automated builds - MSI installer installs to %LOCALAPPDATA%\DangerousThings\NFC Actions - Creates Start Menu shortcut - Automatically starts application on user login 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- Installer/Installer.wixproj | 35 ++++++++++ Installer/Product.wxs | 101 +++++++++++++++++++++++++++ NfcActions/NfcActions.csproj | 28 +++++++- NfcActions/Services/LogService.cs | 5 +- build-release.ps1 | 112 ++++++++++++++++++++++++++++++ 5 files changed, 277 insertions(+), 4 deletions(-) create mode 100644 Installer/Installer.wixproj create mode 100644 Installer/Product.wxs create mode 100644 build-release.ps1 diff --git a/Installer/Installer.wixproj b/Installer/Installer.wixproj new file mode 100644 index 0000000..563088e --- /dev/null +++ b/Installer/Installer.wixproj @@ -0,0 +1,35 @@ + + + + Debug + x86 + 3.11 + f5e6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b + 2.0 + NfcActions-Setup + Package + + + bin\$(Configuration)\ + obj\$(Configuration)\ + Debug + + + bin\$(Configuration)\ + obj\$(Configuration)\ + + + + + + + $(WixExtDir)\WixUIExtension.dll + WixUIExtension + + + + + + + + diff --git a/Installer/Product.wxs b/Installer/Product.wxs new file mode 100644 index 0000000..bad4956 --- /dev/null +++ b/Installer/Product.wxs @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/NfcActions/NfcActions.csproj b/NfcActions/NfcActions.csproj index 5a714ac..8bcec39 100644 --- a/NfcActions/NfcActions.csproj +++ b/NfcActions/NfcActions.csproj @@ -7,6 +7,21 @@ true true Resources\icon.ico + 1.0.0 + 1.0.0.0 + 1.0.0.0 + Dangerous Things + NFC Actions + NFC card reader monitoring and action automation + Copyright © 2025 Dangerous Things + + + + true + true + win-x64 + true + true @@ -22,7 +37,18 @@ - + + Resources\%(RecursiveDir)%(Filename)%(Extension) + PreserveNewest + PreserveNewest + + + + + + + + diff --git a/NfcActions/Services/LogService.cs b/NfcActions/Services/LogService.cs index be97e06..1043832 100644 --- a/NfcActions/Services/LogService.cs +++ b/NfcActions/Services/LogService.cs @@ -21,9 +21,8 @@ public class LogService { _syncContext = SynchronizationContext.Current; - // Create log file in the same directory as the executable - var exePath = Assembly.GetExecutingAssembly().Location; - var exeDir = Path.GetDirectoryName(exePath) ?? Environment.CurrentDirectory; + // Create log file in the app directory (works for single-file publish) + var exeDir = AppContext.BaseDirectory; var timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss"); _logFilePath = Path.Combine(exeDir, $"nfc-actions-debug-{timestamp}.log"); diff --git a/build-release.ps1 b/build-release.ps1 new file mode 100644 index 0000000..dd9a2e5 --- /dev/null +++ b/build-release.ps1 @@ -0,0 +1,112 @@ +# NFC Actions Release Build Script +# This script builds the release version and optionally creates an installer + +param( + [switch]$SkipBuild = $false, + [switch]$BuildInstaller = $true +) + +$ErrorActionPreference = "Stop" +$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path +$projectPath = Join-Path $scriptPath "NfcActions\NfcActions.csproj" +$publishPath = Join-Path $scriptPath "NfcActions\bin\Release\net7.0-windows\win-x64\publish" +$installerPath = Join-Path $scriptPath "Installer" + +Write-Host "=== NFC Actions Release Build ===" -ForegroundColor Cyan +Write-Host "" + +# Step 1: Build and publish the application +if (-not $SkipBuild) { + Write-Host "[1/4] Cleaning previous builds..." -ForegroundColor Yellow + dotnet clean $projectPath -c Release -v quiet + + Write-Host "[2/4] Building release (self-contained, single-file)..." -ForegroundColor Yellow + dotnet publish $projectPath -c Release -r win-x64 --self-contained true /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true /p:PublishReadyToRun=true + + if ($LASTEXITCODE -ne 0) { + Write-Host "Build failed!" -ForegroundColor Red + exit 1 + } + + Write-Host "Build completed successfully!" -ForegroundColor Green + Write-Host "Output: $publishPath" -ForegroundColor Gray + Write-Host "" +} + +# Step 2: Check if WiX is available +if ($BuildInstaller) { + Write-Host "[3/4] Checking for WiX Toolset..." -ForegroundColor Yellow + + $wixInstalled = $false + $candle = Get-Command candle.exe -ErrorAction SilentlyContinue + $light = Get-Command light.exe -ErrorAction SilentlyContinue + + if ($candle -and $light) { + $wixInstalled = $true + Write-Host "WiX Toolset found!" -ForegroundColor Green + } else { + Write-Host "WiX Toolset not found in PATH" -ForegroundColor Yellow + + # Check common installation paths + $wixPaths = @( + "C:\Program Files (x86)\WiX Toolset v3.11\bin", + "C:\Program Files (x86)\WiX Toolset v3.14\bin", + "C:\Program Files\WiX Toolset v3.11\bin", + "C:\Program Files\WiX Toolset v3.14\bin" + ) + + foreach ($path in $wixPaths) { + if (Test-Path (Join-Path $path "candle.exe")) { + $env:Path += ";$path" + $wixInstalled = $true + Write-Host "Found WiX at: $path" -ForegroundColor Green + break + } + } + } + + if ($wixInstalled) { + Write-Host "[4/4] Building MSI installer..." -ForegroundColor Yellow + + Push-Location $installerPath + + # Run candle (compile) + & candle.exe Product.wxs -out obj\Product.wixobj + if ($LASTEXITCODE -ne 0) { + Pop-Location + Write-Host "Candle (WiX compile) failed!" -ForegroundColor Red + exit 1 + } + + # Run light (link) + & light.exe obj\Product.wixobj -out bin\NfcActions-Setup.msi -ext WixUIExtension + if ($LASTEXITCODE -ne 0) { + Pop-Location + Write-Host "Light (WiX link) failed!" -ForegroundColor Red + exit 1 + } + + Pop-Location + + $msiPath = Join-Path $installerPath "bin\NfcActions-Setup.msi" + Write-Host "" + Write-Host "=== Build Complete ===" -ForegroundColor Green + Write-Host "MSI Installer: $msiPath" -ForegroundColor Cyan + + } else { + Write-Host "" + Write-Host "WiX Toolset not found. Skipping MSI creation." -ForegroundColor Yellow + Write-Host "To build the MSI installer, install WiX Toolset from:" -ForegroundColor Yellow + Write-Host " https://github.com/wixtoolset/wix3/releases" -ForegroundColor Gray + Write-Host "" + Write-Host "=== Build Complete ===" -ForegroundColor Green + Write-Host "Executable: $publishPath\NfcActions.exe" -ForegroundColor Cyan + } +} else { + Write-Host "[3/4] Skipping installer build" -ForegroundColor Yellow + Write-Host "" + Write-Host "=== Build Complete ===" -ForegroundColor Green + Write-Host "Executable: $publishPath\NfcActions.exe" -ForegroundColor Cyan +} + +Write-Host ""