forked from wasteam/waslibs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateVersionFiles.ps1
80 lines (62 loc) · 1.87 KB
/
UpdateVersionFiles.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
70
71
72
73
74
75
76
# Enable -Verbose option
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$NewVersion, #Expected Mayor.Minor.Patch
[Parameter(Mandatory=$False,Position=2)]
[string]$Semantic = "",
[Parameter(Mandatory=$False,Position=3)]
[string]$Revision = ""
)
# Regular expression pattern to find the version in the build number
# and then apply it to the assemblies
$VersionRegex = "\d+\.\d+\.\d+\.\d+"
$InformationalVersionRegex = "\d+\.\d+\.\d+\-(\w+)"
$ScriptPath = $null
try
{
$ScriptPath = (Get-Variable MyInvocation).Value.MyCommand.Path
$ScriptDir = Split-Path -Parent $ScriptPath
}
catch {}
if (!$ScriptPath)
{
Write-Error "Current path not found!"
exit 1
}
if($Semantic -ne ""){
$NewInformationalVersion = $NewVersion + "-" + $Semantic
}
else{
$NewInformationalVersion = $NewVersion
}
if($Revision -ne ""){
$NewVersion=$NewVersion + "." + $Revision
if($Semantic -ne ""){
$NewInformationalVersion = $NewInformationalVersion + $Revision
}
else{
$NewInformationalVersion = $NewInformationalVersion + "." + $Revision
}
}
Write-Host "Version: $NewVersion"
Write-Host "Informational Version: $NewInformationalVersion"
Write-Host "ScriptDir: " $ScriptDir
# Apply the version to the assembly property files
$files = gci $ScriptDir -recurse -include "*Properties*","My Project" |
?{ $_.PSIsContainer } |
foreach { gci -Path $_.FullName -Recurse -include AssemblyInfo.* }
if($files)
{
Write-Host "Will apply $NewVersion to $($files.count) files."
foreach ($file in $files) {
$filecontent = Get-Content($file)
attrib $file -r
$filecontent -replace $VersionRegex, $NewVersion | %{ $_ -replace $InformationalVersionRegex, $NewInformationalVersion } | Out-File $file
Write-Host "$file.FullName - version applied"
}
}
else
{
Write-Warning "Found no files."
}