-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbump-version.ps1
48 lines (40 loc) · 1.41 KB
/
bump-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
# Usage Examples:
# .\bump-version.ps1 -VersionType major
# .\bump-version.ps1 -VersionType minor
# .\bump-version.ps1 -VersionType patch
# .\bump-version.ps1 (same as patch)
# If running by double-click, set default to patch
if ([Environment]::GetCommandLineArgs().Length -eq 1) {
$VersionType = "patch"
} else {
param (
[Parameter(Mandatory=$false)]
[ValidateSet("major", "minor", "patch")]
[string]$VersionType = "patch"
)
}
$csprojPath = "SaveHere/SaveHere/SaveHere.csproj"
$content = Get-Content $csprojPath
# Find the current version
$versionPattern = '<Version>(\d+)\.(\d+)\.(\d+)</Version>'
$match = [regex]::Match($content, $versionPattern)
if ($match.Success) {
$major = [int]$match.Groups[1].Value
$minor = [int]$match.Groups[2].Value
$patch = [int]$match.Groups[3].Value
# Increment based on type
switch ($VersionType) {
"major" { $major++; $minor = 0; $patch = 0 }
"minor" { $minor++; $patch = 0 }
"patch" { $patch++ }
}
$newVersion = "$major.$minor.$patch"
$newContent = $content -replace $versionPattern, "<Version>$newVersion</Version>"
Set-Content $csprojPath $newContent
Write-Host "Version bumped to $newVersion"
}
# Keep window open when double-clicked
if ([Environment]::GetCommandLineArgs().Length -eq 1) {
Write-Host "`nPress any key to exit..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}