-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild-Installer.ps1
More file actions
106 lines (92 loc) · 3.88 KB
/
Build-Installer.ps1
File metadata and controls
106 lines (92 loc) · 3.88 KB
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
# ScreenshotSweeper Build and Package Script
# This script builds the application and creates an installer
param(
[switch]$SkipBuild,
[switch]$SkipInstaller
)
$ErrorActionPreference = "Stop"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " ScreenshotSweeper Build Script" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
$ProjectDir = $PSScriptRoot
$PublishDir = Join-Path $ProjectDir "bin\Release\net8.0-windows10.0.19041.0\win-x64\publish"
$InstallerDir = Join-Path $ProjectDir "Installer"
# Step 1: Clean previous builds
if (-not $SkipBuild) {
Write-Host "[1/4] Cleaning previous builds..." -ForegroundColor Yellow
if (Test-Path "bin") { Remove-Item -Path "bin" -Recurse -Force }
if (Test-Path "obj") { Remove-Item -Path "obj" -Recurse -Force }
if (Test-Path $InstallerDir) { Remove-Item -Path $InstallerDir -Recurse -Force }
Write-Host " ✓ Cleaned" -ForegroundColor Green
Write-Host ""
}
# Step 2: Restore dependencies
if (-not $SkipBuild) {
Write-Host "[2/4] Restoring NuGet packages..." -ForegroundColor Yellow
dotnet restore
if ($LASTEXITCODE -ne 0) {
Write-Host " ✗ Restore failed!" -ForegroundColor Red
exit 1
}
Write-Host " ✓ Packages restored" -ForegroundColor Green
Write-Host ""
}
# Step 3: Build and publish
if (-not $SkipBuild) {
Write-Host "[3/4] Building application..." -ForegroundColor Yellow
dotnet publish -c Release -r win-x64 --self-contained false /p:PublishSingleFile=false /p:IncludeNativeLibrariesForSelfExtract=true
if ($LASTEXITCODE -ne 0) {
Write-Host " ✗ Build failed!" -ForegroundColor Red
exit 1
}
Write-Host " ✓ Build completed" -ForegroundColor Green
Write-Host ""
}
# Step 4: Create installer
if (-not $SkipInstaller) {
Write-Host "[4/4] Creating installer..." -ForegroundColor Yellow
# Check if Inno Setup is installed
$InnoSetupPaths = @(
"${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe",
"${env:ProgramFiles}\Inno Setup 6\ISCC.exe",
"${env:ProgramFiles(x86)}\Inno Setup 5\ISCC.exe"
)
$ISCC = $null
foreach ($path in $InnoSetupPaths) {
if (Test-Path $path) {
$ISCC = $path
break
}
}
# Use the manually curated InstallerInfo.rtf for Inno Setup InfoBeforeFile
Write-Host " ✓ Using InstallerInfo.rtf for setup information" -ForegroundColor Green
if ($null -eq $ISCC) {
Write-Host " ⚠ Inno Setup not found!" -ForegroundColor Yellow
Write-Host " Please install Inno Setup from: https://jrsoftware.org/isdl.php" -ForegroundColor Yellow
Write-Host " Then run this script again." -ForegroundColor Yellow
} else {
& $ISCC "Setup.iss"
if ($LASTEXITCODE -ne 0) {
Write-Host " ✗ Installer creation failed!" -ForegroundColor Red
exit 1
}
Write-Host " ✓ Installer created" -ForegroundColor Green
# Show installer location
$InstallerFile = Get-ChildItem -Path $InstallerDir -Filter "*.exe" | Select-Object -First 1
if ($InstallerFile) {
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Build Complete!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Installer location:" -ForegroundColor White
Write-Host " $($InstallerFile.FullName)" -ForegroundColor Cyan
Write-Host ""
Write-Host "Installer size: $([math]::Round($InstallerFile.Length / 1MB, 2)) MB" -ForegroundColor White
}
}
} else {
Write-Host "[4/4] Skipping installer creation" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "Done! 🎉" -ForegroundColor Green