-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathversionup.ps1
69 lines (51 loc) · 2.33 KB
/
versionup.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
param(
[string]$version
)
$solutiondir = $PSScriptRoot
function Generate-Version-Header-File([int]$major, [int]$minor, [int]$patch, [int]$build, [string]$semver){
$copyright_year = Get-Date -Format 'yyyy'
$contents = @"
/* THIS FILE WAS GENERATED BY versionup.ps1 */
/* DO NOT CHANGE MANUALLY !! */
#pragma once
#define MAJOR $major
#define MINOR $minor
#define PATCH $patch
#define BUILD $build
#define SEMVER "$semver"
#define LEGAL_COPYRIGHT "Copyright (C) 2019, $copyright_year, Yasumasa Suenaga"
"@
Set-Content -Path "$solutiondir\common\generated\version.h" -Encoding UTF8 -Value $contents
}
function Update-App-Manifest([int]$major, [int]$minor, [int]$patch, [int]$build){
$manifest_file = "$solutiondir\SimpleCom\app.manifest"
$xml = [xml]::new()
$xml.Load($manifest_file)
$xml.assembly.assemblyIdentity.version = "$major.$minor.$patch.$build"
$xml.Save($manifest_file)
}
function Update-Installer-Version([int]$major, [int]$minor, [int]$patch, [int]$build, [string]$semver){
$product_code = (New-Guid).ToString().ToUpper()
$package_code = (New-Guid).ToString().ToUpper()
$vdproj_path = "$solutiondir\Installer\Installer.vdproj"
$vdproj = Get-Content -Path $vdproj_path -Encoding UTF8
$vdproj = $vdproj -replace '^( +"ProductCode" = "8:{)[0-9A-F\-]+(}")$', ('${1}' + $product_code + '${2}')
$vdproj = $vdproj -replace '^( +"PackageCode" = "8:{)[0-9A-F\-]+(}")$', ('${1}' + $package_code + '${2}')
$vdproj = $vdproj -replace '^( +"ProductVersion" = "8:)[0-9.]+(")$', ('${1}' + "$major.$minor.$patch" + '${2}') # Version number in vdproj looks like x.y.z, cannot include build (revision) number.
$vdproj = $vdproj -replace '^( +"OutputFilename" = "8:).+(")$', ('${1}' + "SimpleComInstaller-$semver.msi" + '${2}')
Set-Content -Path $vdproj_path -Encoding UTF8BOM -Value $vdproj
}
$valid_version = $version -match '^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$'
if(!$valid_version){
Write-Output 'Invalid version string'
return
}
[int]$major = $Matches.1
[int]$minor = $Matches.2
[int]$patch = $Matches.3
[int]$build = $Matches.5 ?? 0
$semver = $build -eq 0 ? "$major.$minor.$patch" : "$major.$minor.$patch+$build"
Write-Output "Version: $semver"
Generate-Version-Header-File $major $minor $patch $build $semver
Update-App-Manifest $major $minor $patch $build
Update-Installer-Version $major $minor $patch $build $semver