forked from jburzynski/TypeGen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-version.ps1
91 lines (75 loc) · 3.21 KB
/
update-version.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
if ($args.Length -eq 0)
{
Write-Host "examples:
./update-version 2.4.9 # changes the current version to 2.4.9"
exit
}
$versionRegex = "^\d+\.\d+\.\d+$"
$newVersion = $args[0]
if (-not ($newVersion -match $versionRegex)) {
Write-Host "Wrong version format. Should be: $($versionRegex)"
exit
}
$oldVersion = (Select-Xml //version "nuget\TypeGen.nuspec")[0].Node.InnerText
$oldVersionMajor = $oldVersion.Split(".")[0]
$oldVersionMinor = $oldVersion.Split(".")[1]
$newVersionMajor = $newVersion.Split(".")[0]
$newVersionMinor = $newVersion.Split(".")[1]
$assemblyOldVersion = "$($oldVersionMajor).$($oldVersionMinor).0.0"
$assemblyNewVersion = "$($newVersionMajor).$($newVersionMinor).0.0"
# replace files' contents
$nuspecPath = "nuget\TypeGen.nuspec"
if (Test-Path $nuspecPath) {
(Get-Content $nuspecPath) `
-Replace "<version>$($oldVersion)</version>", "<version>$($newVersion)</version>" `
| Set-Content $nuspecPath
}
$dotNetCliNuspecPath = "nuget-dotnetcli\dotnet-typegen.nuspec"
if (Test-Path $dotNetCliNuspecPath) {
(Get-Content $dotNetCliNuspecPath) `
-Replace "<version>$($oldVersion)</version>", "<version>$($newVersion)</version>" `
| Set-Content $dotNetCliNuspecPath
}
$appConfigPath = "src\TypeGen\TypeGen.Cli\ApplicationConfig.cs"
if (Test-Path $appConfigPath) {
(Get-Content $appConfigPath) `
-Replace "Version => ""$($oldVersion)""", "Version => ""$($newVersion)""" `
| Set-Content $appConfigPath
}
$nugetUpdatePath = "nuget-update.ps1"
if (Test-Path $nugetUpdatePath) {
(Get-Content $nugetUpdatePath) `
-Replace "TypeGen.$($oldVersion)", "TypeGen.$($newVersion)" `
-Replace "dotnet-typegen.$($oldVersion)", "dotnet-typegen.$($newVersion)" `
| Set-Content $nugetUpdatePath
}
$applicationConfigPath = "src\TypeGen\TypeGen.Cli\ApplicationConfig.cs"
if (Test-Path $applicationConfigPath) {
(Get-Content $applicationConfigPath) `
-Replace "Version = ""$($oldVersion)""", "Version = ""$($newVersion)""" `
| Set-Content $applicationConfigPath
}
$typeGenCliCsprojPath = "src\TypeGen\TypeGen.Cli\TypeGen.Cli.csproj"
if (Test-Path $typeGenCliCsprojPath) {
(Get-Content $typeGenCliCsprojPath) `
-Replace "<AssemblyVersion>$($assemblyOldVersion)</AssemblyVersion>", "<AssemblyVersion>$($assemblyNewVersion)</AssemblyVersion>" `
-Replace "<FileVersion>$($assemblyOldVersion)</FileVersion>", "<FileVersion>$($assemblyNewVersion)</FileVersion>" `
-Replace "<Version>$($oldVersion)</Version>", "<Version>$($newVersion)</Version>" `
| Set-Content $typeGenCliCsprojPath
}
$typeGenCoreCsprojPath = "src\TypeGen\TypeGen.Core\TypeGen.Core.csproj"
if (Test-Path $typeGenCoreCsprojPath) {
(Get-Content $typeGenCoreCsprojPath) `
-Replace "<AssemblyVersion>$($assemblyOldVersion)</AssemblyVersion>", "<AssemblyVersion>$($assemblyNewVersion)</AssemblyVersion>" `
-Replace "<FileVersion>$($assemblyOldVersion)</FileVersion>", "<FileVersion>$($assemblyNewVersion)</FileVersion>" `
| Set-Content $typeGenCoreCsprojPath
}
# remove old NuGet package
$oldNupkgPath = "nuget\TypeGen.$($oldVersion).nupkg"
if (Test-Path $oldNupkgPath) {
rm $oldNupkgPath
}
$oldDotNetCliNupkgPath = "nuget-dotnetcli\dotnet-typegen.$($oldVersion).nupkg"
if (Test-Path $oldDotNetCliNupkgPath) {
rm $oldDotNetCliNupkgPath
}