-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
AssemblyInfoPatcher.ps1
45 lines (39 loc) · 1.43 KB
/
AssemblyInfoPatcher.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
param(
[parameter(Mandatory=$true)]
[string]$version
)
(Get-childitem -Path ".") | Foreach-Object {
Write-Host "$_"
}
$parts = $version -split '-'
$arr = $parts[0] -split '\.'
if ($arr.Count -eq 2) {$arr+=0}
if ($parts.Count -gt 1) {
$arr += $parts[1..($parts.Length-1)]
}
if ($arr.Count -eq 2) {$arr+=0}
if ($arr.Count -eq 3) {$arr+=0}
Write-Host "Major: $($arr[0])"
Write-Host "Minor: $($arr[1])"
Write-Host "Patch: $($arr[2])"
Write-Host "Build number: $($arr[3])"
(Get-childitem -Path . -include AssemblyInfo.cs -recurse) | Foreach-Object {
$path = $_
(Get-Content $_) | ForEach-Object{
if($_ -match '\[assembly: AssemblyVersion\("(.*)"\)\]'){
$newVersion = "{0}.{1}.{2}" -f $arr[0], $arr[1], $arr[2]
'[assembly: AssemblyVersion("{0}")]' -f $newVersion
Write-Host("Setting version to $newVersion in $path")
} elseif($_ -match '\[assembly: AssemblyFileVersion\("(.*)"\)\]'){
$newVersion = "{0}.{1}.{2}" -f $arr[0], $arr[1], $arr[2]
'[assembly: AssemblyFileVersion("{0}")]' -f $newVersion
Write-Host("Setting file version to $newVersion in $path")
} elseif($_ -match '\[assembly: AssemblyInformationalVersion\("(.*)"\)\]'){
$newVersion = "{0}.{1}.{2}" -f $arr[0], $arr[1], $arr[2]
'[assembly: AssemblyInformationalVersion("{0}")]' -f $version
Write-Host("Setting informational version to $version in $path")
} else {
$_
}
} | Set-Content $_
}