-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
140 lines (115 loc) · 3.76 KB
/
build.ps1
File metadata and controls
140 lines (115 loc) · 3.76 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#Requires -Version 5.1
<#
.SYNOPSIS
Build script for ImageProcessor application
.DESCRIPTION
Builds and publishes the ImageProcessor Windows Forms application
as a self-contained executable.
.PARAMETER Configuration
Build configuration (Debug or Release). Default: Release
.PARAMETER Runtime
Target runtime. Default: win-x64
Options: win-x64, win-x86, win-arm64
.PARAMETER Clean
Clean build output before building
.PARAMETER Package
Create a ZIP package after building
.EXAMPLE
.\build.ps1
Build with default settings
.EXAMPLE
.\build.ps1 -Configuration Debug -Clean
Clean build in Debug mode
.EXAMPLE
.\build.ps1 -Package
Build and create ZIP package
#>
param(
[ValidateSet('Debug', 'Release')]
[string]$Configuration = 'Release',
[ValidateSet('win-x64', 'win-x86', 'win-arm64')]
[string]$Runtime = 'win-x64',
[switch]$Clean,
[switch]$Package
)
$ErrorActionPreference = 'Stop'
# Configuration
$ProjectName = 'ImageProcessor'
$SolutionFile = 'ImageProcessor.sln'
$PublishDir = 'publish'
$ProjectFile = "$ProjectName\$ProjectName.csproj"
Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
Write-Host "Building $ProjectName" -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Configuration: $Configuration"
Write-Host "Runtime: $Runtime"
Write-Host ""
# Clean if requested
if ($Clean -and (Test-Path $PublishDir)) {
Write-Host "[0/4] Cleaning previous build..." -ForegroundColor Yellow
Remove-Item -Path $PublishDir -Recurse -Force
}
# Restore
Write-Host "[1/4] Restoring dependencies..." -ForegroundColor Yellow
dotnet restore $SolutionFile
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Restore failed!" -ForegroundColor Red
exit 1
}
# Build
Write-Host ""
Write-Host "[2/4] Building solution..." -ForegroundColor Yellow
dotnet build $SolutionFile --configuration $Configuration --no-restore
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Build failed!" -ForegroundColor Red
exit 1
}
# Publish
Write-Host ""
Write-Host "[3/4] Publishing self-contained executable..." -ForegroundColor Yellow
$OutputPath = Join-Path $PublishDir $Runtime
dotnet publish $ProjectFile `
--configuration $Configuration `
--runtime $Runtime `
--self-contained true `
--output $OutputPath `
-p:PublishSingleFile=true `
-p:IncludeNativeLibrariesForSelfExtract=true `
-p:EnableCompressionInSingleFile=true
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Publish failed!" -ForegroundColor Red
exit 1
}
# Create version file
Write-Host ""
Write-Host "[4/4] Creating version info..." -ForegroundColor Yellow
$VersionInfo = @"
Build Date: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')
Configuration: $Configuration
Runtime: $Runtime
Machine: $env:COMPUTERNAME
"@
$VersionInfo | Out-File -FilePath (Join-Path $OutputPath 'version.txt') -Encoding UTF8
# Package if requested
if ($Package) {
Write-Host ""
Write-Host "Creating ZIP package..." -ForegroundColor Yellow
$ZipName = "$ProjectName-$Runtime-$(Get-Date -Format 'yyyyMMdd').zip"
$ZipPath = Join-Path $PublishDir $ZipName
Compress-Archive -Path "$OutputPath\*" -DestinationPath $ZipPath -Force
Write-Host "Package created: $ZipPath" -ForegroundColor Green
}
# Summary
Write-Host ""
Write-Host "============================================" -ForegroundColor Green
Write-Host "Build completed successfully!" -ForegroundColor Green
Write-Host "============================================" -ForegroundColor Green
Write-Host ""
Write-Host "Output directory: $OutputPath"
Write-Host ""
Write-Host "Files:" -ForegroundColor Cyan
Get-ChildItem $OutputPath | Format-Table Name, Length -AutoSize
# Return the output path
return $OutputPath