-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGenerateInstaller.ps1
116 lines (96 loc) · 4.55 KB
/
GenerateInstaller.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
114
115
116
<#
.SYNOPSIS
Generates an installer. (c) 2022 Javi Pulido
.DESCRIPTION
This script generates a setup package. It uses Inno Setup.
.EXAMPLE
.\<script_name> -buildOutputPath WinRemoteControl\bin\Release\net5.0-windows\win-x86\publish setupExecutableNameIncludingEXEExtension WinRemoteControl_Setup_32 -CsprojPath .\WinRemoteControl\WinRemoteControl.csproj [-buildIdentifier 1.0.1] [-$baseDirectory $PSScriptRoot] [-installerOutputPath Installer\Output]
.LINK
https://github.com/pulimento
#>
param
(
[Parameter(HelpMessage="If true, it can be used to create local builds")][bool]$pathsAreRelativeToBaseDirectory = $false,
[string]$buildOutputPath = "WinRemoteControl\bin\Release\net6.0-windows\win-x86\publish",
[string]$CsprojPath = "WinRemoteControl\WinRemoteControl.csproj",
[string]$SetupIconFile = "WinRemoteControl\Resources\big_icon_5jt_icon.ico",
[Parameter(HelpMessage="Overrides build identifier, script tries to get it automatically")]$buildIdentifier,
[string]$baseDirectory = "$PSScriptRoot",
[string]$installerOutputPath = "Installer\Output",
[string]$setupExecutableName = "WinRemoteControl_Setup_32"
)
################################################################
##### FUNCTIONS
################################################################
function LogWarning($line)
{ Write-Host "##[warning] $line" -Foreground DarkYellow -Background Black
}
function LogDebug($line)
{ Write-Host "##[debug] $line" -Foreground Blue -Background Black
}
function LogSection($line)
{ Write-Host "##[section] $line" -Foreground Green -Background Black
}
################################################################
##### GLOBAL VARIABLES
################################################################
# Set working directory
Push-Location (Get-Location).Path
Set-Location $baseDirectory
# Constants
$installerFolderPath = Join-Path (Get-Location).Path "Installer"
$innoSetupScriptPath = Resolve-Path (Join-Path $installerFolderPath "InstallerScript.iss")
$innoSetupResourcesPath = Resolve-Path (Join-Path $installerFolderPath "InnoSetupResources")
if($pathsAreRelativeToBaseDirectory)
{
$buildOutputPath = Join-Path $baseDirectory $buildOutputPath
$CsprojPath = Join-Path $baseDirectory $CsprojPath
$SetupIconFile = Join-Path $baseDirectory $SetupIconFile
$installerOutputPath = Join-Path $baseDirectory $installerOutputPath
}
############################################################################################################################################
##### STAGES
############################################################################################################################################
LogDebug "################## VARIABLES ##################"
LogDebug "Build source path : $buildOutputPath"
LogDebug "Inno Setup Script path : $innoSetupScriptPath"
LogDebug "Inno Setup Resources path: $innoSetupResourcesPath"
LogDebug "Installer output : $installerOutputPath"
LogDebug "Setup EXE name : $setupExecutableName"
LogDebug ".csproj path : $CsprojPath"
LogDebug "###############################################"
################################################################
##### STAGE: PRE-COMPILATION
################################################################
LogSection "START Pre-compilation tasks"
# FIND INNO SETUP
$innoSetupCompilerPath = Resolve-Path (Join-Path $innoSetupResourcesPath "ISCC.exe")
if (-Not (Test-Path $innoSetupCompilerPath))
{ throw "InnoSetup compiler not found. Exiting..."
}
# Get version from csproj
if($null -eq $buildIdentifier )
{
LogDebug "Build identifier not set, try to obtain it from .csproj"
$xml = [Xml] (Get-Content $CsprojPath)
$buildIdentifier = [version] $xml.Project.PropertyGroup[1].Version
}
LogSection "END Pre-compilation tasks"
################################################################
##### STAGE: GENERATE INSTALLER
################################################################
LogSection "START generating installer"
LogDebug "InnoSetupCompilerPath $innoSetupCompilerPath"
LogDebug "BuildIdentifier $buildIdentifier"
LogDebug "OutputDir $installerOutputPath"
LogDebug "SourceDir $buildOutputPath"
LogDebug "SetupIconFile $SetupIconFile"
LogDebug "InnoSetupScriptPath $innoSetupScriptPath"
& $innoSetupCompilerPath /DMyAppVersion="$buildIdentifier" /DMyOutputDir="$installerOutputPath" /DMySourceDir="$buildOutputPath" /DMySetupIconFile="$SetupIconFile" $innoSetupScriptPath -DMyOutputBaseFileName="$setupExecutableName"
if(-Not $?)
{
LogWarning "lastexitcode $lastexitcode"
exit $lastexitcode
}
LogSection "END generating installer"
Pop-Location