This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
forked from michaelnoonan/inputsimulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetVersion.ps1
69 lines (51 loc) · 2.4 KB
/
SetVersion.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
$SCRIPTVERSION = "1.0" # The version number of this script file
##############################################
# You can add any number of additional entries to this variable by appending them like this: "", "", ""
$projectNames = "InputSimulatorEx";
$versionVariableNames = "Version"
$rawVersionVariableNames = "ExtendedVersion"
##########< Don't Edit Past Here >##########
# Get git tag
if (($raw_tag = git describe --tags --abbrev=0).Length -eq 0) { throw "No git tag found!"; }
# Parse git tag
$raw_tag -cmatch '(?<MAJOR>\d+?)\.(?<MINOR>\d+?)\.(?<PATCH>\d+?)(?<EXTRA>.*)'
$parsed_tag = $Matches.MAJOR + '.' + $Matches.MINOR + '.' + $Matches.PATCH
Write-Output "Parsed Git Tag `"$raw_tag`":",
" - MAJOR: `"$($Matches.MAJOR)`"",
" - MINOR: `"$($Matches.MINOR)`"",
" - PATCH: `"$($Matches.PATCH)`"",
" - EXTRA: `"$($Matches.EXTRA)`"",
"3-Part Version Number: `"$parsed_tag`""
if ($versionVariableNames.Count -eq 0) {
Write-Error "Invalid configuration: `$versionVariableNames = `"$versionVariableNames`" ; expected a list of strings!"
}
$myPath = Get-Location
foreach ($path in $projectNames)
{
$dirpath = [System.IO.PAth]::Combine($myPath, $path);
$projectFiles = Get-ChildItem -File -Path $dirpath -Filter "*.csproj"
if ($projectFiles.Count -eq 0) {
Write-Error "No files matching filter `"*.csproj`" found in project `"$dirpath`""
}
foreach ($project in $projectFiles) {
[xml]$CONTENT = Get-Content -Path $project
Write-Output "","Opened Project File: `"$project`""
Write-Output $CONTENT.Project
foreach ($varName in $versionVariableNames) {
$tmp = $CONTENT.Project.PropertyGroup.$varName
$CONTENT.Project.PropertyGroup.$varName = $parsed_tag
Write-Output "-> Property: `"$varName`"",
" Outgoing: `"$tmp`"",
" Incoming: `"$parsed_tag`""
}
foreach ($varName in $rawVersionVariableNames) {
$tmp = $CONTENT.Project.PropertyGroup.$varName
$CONTENT.Project.PropertyGroup.$varName = $raw_tag
Write-Output "-> Property: `"$varName`"",
" Outgoing: `"$tmp`"",
" Incoming: `"$parsed_tag`""
}
$CONTENT.Save($project)
Write-Output "-> Saved Project File."
}
}