-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpackageRelease.ps1
47 lines (36 loc) · 1.63 KB
/
packageRelease.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
# Define paths
$outputPath = ".\"
$tempPath = "$env:TEMP\GChanReleaseBuild"
$zipNameTemplate = "GChan{0}.zip"
$folderNameTemplate = "GChan{0}"
# Clean up previous temp directory if it exists
if (Test-Path $tempPath) {
Remove-Item -Recurse -Force $tempPath
}
# Create new temp directory
New-Item -ItemType Directory -Force -Path $tempPath
# Get the assembly version
$assemblyInfoPath = ".\GChan\Properties\AssemblyInfo.cs"
$assemblyVersion = Select-String -Pattern 'AssemblyVersion\("([0-9\.]+)"\)' -Path $assemblyInfoPath | ForEach-Object { $_.Matches.Groups[1].Value }
if (-not $assemblyVersion) {
Write-Error "Assembly version not found in AssemblyInfo.cs"
exit 1
}
# Build the release configuration using msbuild
& msbuild GChan /p:Configuration=Release /p:OutputPath=$tempPath
if ($LASTEXITCODE -ne 0) {
Write-Error "Build failed"
exit 1
}
# Create a new directory inside tempPath with the versioned folder name
$versionedFolderName = [string]::Format($folderNameTemplate, $assemblyVersion)
$versionedFolderPath = Join-Path -Path $tempPath -ChildPath $versionedFolderName
New-Item -ItemType Directory -Force -Path $versionedFolderPath
# Move all build output to the versioned folder
Get-ChildItem -Path $tempPath -Exclude $versionedFolderName | Move-Item -Destination $versionedFolderPath
# Create the zip file
$zipFileName = [string]::Format($zipNameTemplate, $assemblyVersion)
$zipFilePath = Join-Path -Path $outputPath -ChildPath $zipFileName
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::CreateFromDirectory($tempPath, $zipFilePath)
Write-Host "Build and packaging complete: $zipFilePath"