forked from dziemborowicz/hourglass
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Update-Version.ps1
69 lines (50 loc) · 2.13 KB
/
Update-Version.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<#
.SYNOPSIS
Gets project version from latest.xml and updates it for dependent files.
.DESCRIPTION
Gets project version from latest.xml and updates it for dependent files. Prints version and update URL.
.EXAMPLE
pwsh ./Update-Version.ps1
Gets project version from latest.xml and updates it for dependent files.
#>
[CmdletBinding()]
param()
#requires -Version 7
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$Verbose = $VerbosePreference -ne 'SilentlyContinue'
$PSDefaultParameterValues['*:Verbose'] = $Verbose
$PSDefaultParameterValues['*:ErrorAction'] = $ErrorActionPreference
$ThisFolder = Split-Path (Get-Item (&{ $MyInvocation.ScriptName }))
function Main
{
$latestFile = Join-Path $ThisFolder latest.xml
$buildPropsFile = Join-Path $ThisFolder Directory.Build.props
$appManifestFile = Join-Path $ThisFolder Hourglass\Properties\app.manifest
$bundleWxsFile = Join-Path $ThisFolder Hourglass.Bundle\Bundle.wxs
$productWxsFile = Join-Path $ThisFolder Hourglass.Setup\Product.wxs
Write-Output "Reading '$latestFile'..."
$latestXml = ([xml](Get-Content $latestFile)).UpdateInfo
$latest = [PSCustomObject]@{
Version = $latestXml.LatestVersion
UpdateUrl = $latestXml.UpdateUrl
}
$fieldsFormat =
@{ n = 'Version'; e = { $_.Version } },
@{ n = 'UpdateUrl'; e = { $_.UpdateUrl } }
Write-Output "`n$(($latest | Format-List $fieldsFormat | Out-String).Trim())`n"
Update-Content $appManifestFile '(?<=assemblyIdentity\s+version=")[^"]+(?=[\s\S]+?name)',$latest.Version
Update-Content $buildPropsFile '(?<=\<Version\>)[^<]+',$latest.Version
Update-Content $bundleWxsFile '(?<=\s+Version=")[^"]+',$latest.Version
Update-Content $productWxsFile '(?<=\s+Version=")[^"]+',$latest.Version
}
function Update-Content($file, $replace)
{
Write-Output "Updating '$file'..."
$reader = [IO.StreamReader]::new($file, [Text.Encoding]::Default, $true)
[void]$reader.Peek()
$encoding = $reader.CurrentEncoding
$reader.Close()
(Get-Content $file -Raw) -creplace $replace | Set-Content $file -NoNewline -Encoding $encoding
}
. Main