This repository has been archived by the owner on Sep 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
/
UpdateAmbrosiaForNugetRelease.ps1
116 lines (95 loc) · 7.17 KB
/
UpdateAmbrosiaForNugetRelease.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
###########################################
#
# Script to update Ambrosia to the new Nuget Release
#
# Call:
# .\UpdateAmbrosiaForNugetRelease.ps1 2.0.0 2.1.0
#
# Parameters:
# CurrentVersion - Version of the Nuget
# NewVersion - Version upgrading to. If NewVersion is same as CurrentVersion, it will just rebuild everything
#
# Note: Run this script AFTER the .nuspec files have been updated (and checked in)
# and the Ambrosia nuget packages (Microsoft.Ambrosia.LibCS and Microsoft.Ambrosia.LibCSDebug) have been released to Nuget.org
# FYI - To release those Nuget packages, run the Ambrosia-Nuget-Release and Ambrosia-Nuget-Debug pipelines in Azure Dev Ops for Ambrosia
#
###########################################
$CurrentVersion=$args[0]
$NewVersion=$args[1]
# Verify parameters are passed
if ([string]::IsNullOrEmpty($CurrentVersion)) {
Write-output "ERROR! Missing the first parameter (CurrentVersion). "
exit
}
if ([string]::IsNullOrEmpty($NewVersion)) {
Write-output "ERROR! Missing the second parameter (NewVersion). "
exit
}
##########################################################################
# Wrapper around swapping out Nuget Versions in CSProj files.
#
# Need to set proper encoding as files use different ones. Want to save in same encoding that created in
# Generated code = UTF8NoBOM (aka "(Western European (windows)") - default for Set-Content.
# Source code = UTF8
#
# Sample strings that will need to be replaced
# <PackageReference Include="AmbrosiaLibCS" Version="1.0.11" Condition="'$(Configuration)' == 'Release' " />
# <PackageReference Include="AmbrosiaLibCSDebug" Version="1.0.11" Condition="'$(Configuration)' == 'Debug'" />
##########################################################################
function SwapNugetStringInFile {
Param ($OldVer,$NewVer,$FileName, $NoBOMEncoding)
$message = "File: $FileName Nuget Ver: $OldVer -> $NewVer";
Write-Output $message;
# Replace for AmbrosiaLibCS and AmbrosiaLibCSDebug
$FullOldVerString = '"Microsoft.Ambrosia.LibCS" Version="'+$OldVer+'"';
$FullNewVerString = '"Microsoft.Ambrosia.LibCS" Version="'+$NewVer+'"';
$FullOldVerDebugString = '"Microsoft.Ambrosia.LibCSDebug" Version="'+$OldVer+'"';
$FullNewVerDebugString = '"Microsoft.Ambrosia.LibCSDebug" Version="'+$NewVer+'"';
# Make the call based on what encoding to use
If ($NoBOMEncoding -eq 'T') #UTF8NoBom used for Generated Code
{
(Get-Content $FileName).replace($FullOldVerString, $FullNewVerString) | Set-Content $FileName;
(Get-Content $FileName).replace($FullOldVerDebugString, $FullNewVerDebugString) | Set-Content $FileName;
}
else # Standard UTF8 used in Source code
{
(Get-Content $FileName).replace($FullOldVerString, $FullNewVerString) | Set-Content -Encoding UTF8 $FileName;
(Get-Content $FileName).replace($FullOldVerDebugString, $FullNewVerDebugString) | Set-Content -Encoding UTF8 $FileName;
}
}
##########################################################################
#
# Make the calls here to update csproj files
#
##########################################################################
Write-output "------------- Update .csproj files -------------"
$CurrentDir = $(get-location);
# AmbrosiaCS
SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\Clients\CSharp\AmbrosiaCS\AmbrosiaCS.csproj' -NoBOMEncoding 'F';
# PerformanceTest - discontinued
#SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\InternalImmortals\PerformanceTest\GeneratedSourceFiles\PTAmbrosiaGeneratedAPI\latest\PTAmbrosiaGeneratedAPI.csproj' -NoBOMEncoding 'T';
# PerformanceTestInterruptible
SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\InternalImmortals\PerformanceTestInterruptible\API\ServerAPI.csproj' -NoBOMEncoding 'F';
SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\InternalImmortals\PerformanceTestInterruptible\GeneratedSourceFiles\PTIAmbrosiaGeneratedAPI\latest\PTIAmbrosiaGeneratedAPI.csproj' -NoBOMEncoding 'T';
# HelloWorld
SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\Samples\HelloWorld\GeneratedSourceFiles\Client1Interfaces\latest\Client1Interfaces.csproj' -NoBOMEncoding 'T';
SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\Samples\HelloWorld\GeneratedSourceFiles\Client2Interfaces\latest\Client2Interfaces.csproj' -NoBOMEncoding 'T';
SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\Samples\HelloWorld\GeneratedSourceFiles\Client3Interfaces\latest\Client3Interfaces.csproj' -NoBOMEncoding 'T';
SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\Samples\HelloWorld\GeneratedSourceFiles\ServerInterfaces\latest\ServerInterfaces.csproj' -NoBOMEncoding 'T';
#SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\Samples\HelloWorld\IClient1\IClient1.csproj' -NoBOMEncoding 'F';
SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\Samples\HelloWorld\IClient2\IClient2.csproj' -NoBOMEncoding 'F';
#SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\Samples\HelloWorld\IClient3\IClient3.csproj' -NoBOMEncoding 'F';
#SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\Samples\HelloWorld\ServerAPI\IServer.csproj' -NoBOMEncoding 'F';
# StreamingDemo
SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\Samples\StreamingDemo\AnalyticsAPI\AnalyticsAPI.csproj' -NoBOMEncoding 'F';
SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\Samples\StreamingDemo\GeneratedSourceFiles\AnalyticsAPIGenerated\latest\AnalyticsAPIGenerated.csproj' -NoBOMEncoding 'T';
#SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\Samples\StreamingDemo\DashboardAPI\DashboardAPI.csproj' -NoBOMEncoding 'F';
SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\Samples\StreamingDemo\Dashboard\Dashboard.csproj' -NoBOMEncoding 'F';
SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\Samples\StreamingDemo\GeneratedSourceFiles\DashboardAPIGenerated\latest\DashboardAPIGenerated.csproj' -NoBOMEncoding 'T';
#XamarinCommandShell
SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\InternalImmortals\XamarinCommandShell\ICommandShellImmortal\ICommandShellImmortal.csproj' -NoBOMEncoding 'F';
SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\InternalImmortals\XamarinCommandShell\GeneratedSourceFiles\ICommandShellImmortalGenerated\latest\ICommandShellImmortalGenerated.csproj' -NoBOMEncoding 'F';
SwapNugetStringInFile -OldVer $CurrentVersion -NewVer $NewVersion -FileName $CurrentDir'\InternalImmortals\XamarinCommandShell\XamarinCommandShell.GTK\XamarinCommandShell.GTK.csproj' -NoBOMEncoding 'F';
Write-output "--------------------------------------------"
Write-output "------------- DONE!!! -------------"
Write-output "--------------------------------------------"