-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathUtils.ps1
64 lines (53 loc) · 1.89 KB
/
Utils.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
function Get-AssemblyVersionFromAssemblyInfo {
param(
[Parameter(Mandatory=$True)][string] $File
)
# Load version from AssemblyInfo.cs
$fileContent = Get-Content $file
$regex = [regex] "^\[assembly\: AssemblyVersion\(`"([0-9]+\.[0-9]+\.[0-9]+)(\.[0-9]+)?`"\)\]"
foreach($line in $fileContent) {
if ($line -imatch $regex) {
$version = $matches[1]
$found = $True
break
}
}
if (-Not $found){
Throw "Could not find [assembly: AssemblyVersion(`"`") attribute inside of $File."
}
return $version
}
function Patch-AssemblyInfoVersions {
[CmdLetBinding()]
param(
[Parameter(Mandatory=$True)][string] $File,
[Parameter(Mandatory=$True)][string] $AssemblyVersion,
[Parameter(Mandatory=$True)][string] $FileVersion,
[Parameter(Mandatory=$True)][string] $InformationalVersion
)
$fileContent = Get-Content $File -Raw
$fileContent = [Regex]::Replace($fileContent, 'AssemblyVersion\("[^"]*"\)', "AssemblyVersion(`"$AssemblyVersion`")")
$fileContent = [Regex]::Replace($fileContent, 'AssemblyFileVersion\("[^"]*"\)', "AssemblyFileVersion(`"$FileVersion`")")
$fileContent = [Regex]::Replace($fileContent, 'AssemblyInformationalVersion\("[^"]*"\)', "AssemblyInformationalVersion(`"$InformationalVersion`")")
Set-Content $File $fileContent
}
function Generate-FileAndInformationalVersion {
[CmdLetBinding()]
param(
[Parameter(Mandatory=$True)][string] $AssemblyVersion,
[Parameter(Mandatory=$True)][string] $BuildCounter,
[Parameter(Mandatory=$True)][string] $Branch,
[Parameter(Mandatory=$False)][bool] $IsRelease
)
$fileVersion = "$AssemblyVersion.$BuildCounter"
$informationalVersion = "$AssemblyVersion.$BuildCounter"
if ($IsRelease -eq $False) {
if ($Branch -eq "master") {
$informationalVersion += "-dev"
} elseif ( $Branch -match "feature-.*" -or
$Branch -match "bugfix-.*") {
$informationalVersion += "-$Branch"
}
}
return $fileVersion,$informationalVersion
}