1+ <#
2+ . SYNOPSIS
3+ Update project and installer version numbers from version.txt.
4+
5+ . DESCRIPTION
6+ Replaces product/version fields in .csproj files and the VERSION define in the installer
7+ Version.wxi. Intended to run from the repository Scripts folder (the script sets location
8+ to its own folder automatically).
9+
10+ .USAGE
11+ .\update-versions.ps1 # reads version from version.txt
12+ .\update-versions.ps1 -NewVersion 1.6.0
13+ #>
14+
15+ param (
16+ [string ]$NewVersion
17+ )
18+
19+ Set-StrictMode - Version Latest
20+
21+ try {
22+ # ensure script runs from its directory (matches batch behavior)
23+ Set-Location - Path $PSScriptRoot
24+
25+ if (-not $NewVersion ) {
26+ $versionFile = Join-Path $PSScriptRoot ' version.txt'
27+ if (-not (Test-Path $versionFile )) {
28+ Write-Error " version.txt not found at $versionFile "
29+ exit 1
30+ }
31+
32+ $raw = Get-Content - Path $versionFile - Raw - ErrorAction Stop
33+ $NewVersion = $raw.Trim ()
34+ }
35+
36+ if ([string ]::IsNullOrWhiteSpace($NewVersion )) {
37+ Write-Error ' No version found or provided.'
38+ exit 1
39+ }
40+
41+ Write-Host " New Version: $NewVersion "
42+
43+ $txd = ' Trixter.XDream'
44+
45+ function Replace-InFile {
46+ param (
47+ [Parameter (Mandatory = $true )][string ]$Path ,
48+ [Parameter (Mandatory = $true )][string ]$NewVersion ,
49+ [Parameter (Mandatory = $true )][bool ]$isCsproj
50+ )
51+
52+ if (-not (Test-Path $Path )) {
53+ Write-Error " File not found: $Path "
54+ return $false
55+ }
56+
57+ # Read/Write using UTF8 to match original script behavior
58+ [xml ]$content = Get-Content - Path $Path - Raw - Encoding UTF8
59+
60+ if ($isCsProj ) {
61+ $content.Project.PropertyGroup.Version = $NewVersion
62+ } else {
63+ $content.Include.define = ' VERSION = "' + $NewVersion + ' "'
64+ }
65+ $content.Save ($Path )
66+ Write-Host " Updated: $Path "
67+
68+ return $true
69+ }
70+
71+ Write-Host ' Updating API'
72+ $apiProj = Join-Path $PSScriptRoot " ..\$txd .API\$txd .API.csproj"
73+ Replace- InFile - Path $apiProj - NewVersion $NewVersion - isCsproj $true
74+
75+ Write-Host ' Updating Diagnostics'
76+ $diagProj = Join-Path $PSScriptRoot " ..\$txd .Diagnostics\$txd .Diagnostics.csproj"
77+ Replace- InFile - Path $diagProj - NewVersion $NewVersion - isCsproj $true
78+
79+ Write-Host ' Updating Test Controller'
80+ $tcProj = Join-Path $PSScriptRoot " ..\$txd .TestController\$txd .TestController.csproj"
81+ Replace- InFile - Path $tcProj - NewVersion $NewVersion - isCsproj $true
82+
83+ Write-Host ' Updating installer project'
84+ $wxi = Join-Path $PSScriptRoot " ..\$txd .Installer\Version.wxi"
85+ Replace- InFile - Path $wxi - NewVersion $NewVersion - isCsproj $false
86+
87+ Write-Host ' Done.'
88+ exit 0
89+ }
90+ catch {
91+ Write-Error $_.Exception.Message
92+ exit 1
93+ }
0 commit comments