-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateVersion.ps1
More file actions
42 lines (33 loc) · 1.02 KB
/
UpdateVersion.ps1
File metadata and controls
42 lines (33 loc) · 1.02 KB
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
param (
[Parameter(Mandatory=$true)]
[string]$ManifestPath
)
try {
if (-not (Test-Path $ManifestPath)) {
Write-Error "File not found: $ManifestPath"
exit 1
}
# Generate the 5-digit version (YearLastDigit + Month + Day)
$dateVersion = Get-Date -Format "yMMdd"
$dateVersion = $dateVersion.Substring($dateVersion.Length - 5)
# Load XML
[xml]$manifest = Get-Content $ManifestPath
# Use LocalName to find Identity (ignores Namespace prefix issues)
$identity = $manifest.Package.Identity
if ($null -eq $identity) {
Write-Error "Could not find <Identity> node in manifest."
exit 1
}
# Update the 3rd part of the version
$versionParts = $identity.Version.Split('.')
$versionParts[2] = $dateVersion
$newVersion = [string]::Join(".", $versionParts)
$identity.Version = $newVersion
$manifest.Save($ManifestPath)
Write-Host "Updated $ManifestPath to $newVersion"
exit 0
}
catch {
Write-Error $_.Exception.Message
exit 1
}