-
Notifications
You must be signed in to change notification settings - Fork 1
/
UpdateMAQSVersion.ps1
67 lines (57 loc) · 2.06 KB
/
UpdateMAQSVersion.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
<#
.SYNOPSIS
Makes updates to the MAQS project templates.
.DESCRIPTION
This powershell script is used to update the MAQS csproj files to specific versions
.PARAMETER MAQSVersion
The desired version of MAQS to set.
.PARAMETER BetaVersion
The desired version of the beta release to set.
.NOTES
Version: 2.0
Author: Magenic
Creation Date: 05/7/2021
Purpose/Change: Chang over to replacing VersionPrefix and VersionSuffix values.
Version: 1.0
Author: Magenic
Creation Date: 03/24/2021
Purpose/Change: Initial script development.
.EXAMPLE
./UpdateMAQSVersion -MAQSVersion "4.0.0" -BetaVersion "-beta.1"
This command will update the MAQS version to the specific version with the next beta tag.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$MAQSVersion,
[string]$BetaVersion
)
function UpdateFiles($directory, $fileFilter, $maqsVersion, $BetaVersion) {
Get-ChildItem $directory -Filter $fileFilter -Recurse |
ForEach-Object {
Write-Host "Checking File " $_.FullName
UpdateFileContent $_.FullName $maqsVersion $BetaVersion
}
}
function UpdateFileContent($file, $maqsVersion, $betaVersion) {
$filetext = [System.IO.File]::ReadAllText($file)
$filetext = UpdateLine $filetext $maqsVersion $betaVersion
[System.IO.File]::WriteAllText($file, $filetext, [System.Text.Encoding]::UTF8)
}
function UpdateLine($fileText, $maqsVersion, $betaVersion) {
$originalText = $filetext
$regexPattern = "(<VersionPrefix>)(.*)(</VersionPrefix>)"
$maqsVersion = "`${1}" + $maqsVersion + "`${3}"
$filetext = $filetext -replace $regexPattern, $maqsVersion
$regexPattern = "(<VersionSuffix>)(.*)(</VersionSuffix>)"
$betaVersion = "`${1}" + $betaVersion + "`${3}"
$filetext = $filetext -replace $regexPattern, $betaVersion
if ($originalText -eq $filetext) {
Write-Host "No Changes to file"
}
else {
Write-Host "File Updated"
}
return $filetext
}
UpdateFiles $PSScriptRoot "*.csproj" $MAQSVersion $BetaVersion