Repository navigation
Expand file tree
/
Copy pathpack.ps1
More file actions
76 lines (66 loc) · 3.17 KB
/
Copy pathpack.ps1
File metadata and controls
76 lines (66 loc) · 3.17 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
<#
.SYNOPSIS
Builds the xpp-lens distribution package (ZIP) for installing on another machine.
.DESCRIPTION
By default publishes a self-contained build (single EXE): nothing needs to be installed
on the target machine. With -FrameworkDependent the package is small but requires the
.NET 9 Runtime on the target machine.
.EXAMPLE
.\pack.ps1
.EXAMPLE
.\pack.ps1 -FrameworkDependent
#>
[CmdletBinding()]
param(
[string] $OutDir = (Join-Path $PSScriptRoot 'dist'),
[switch] $FrameworkDependent,
[switch] $NoZip
)
$ErrorActionPreference = 'Stop'
$proj = Join-Path $PSScriptRoot 'src\XppLens\XppLens.csproj'
$stage = Join-Path $OutDir 'xpp-lens'
$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1'
if (Test-Path $stage) { Remove-Item $stage -Recurse -Force }
New-Item -ItemType Directory -Force -Path $stage | Out-Null
$publishArgs = @(
'publish', $proj, '-c', 'Release', '-r', 'win-x64',
'-o', (Join-Path $stage 'bin'), '--nologo',
# No debug information: a release build would otherwise carry the local path of its .pdb file.
'-p:DebugType=None', '-p:DebugSymbols=false'
)
if ($FrameworkDependent) {
$publishArgs += @('--self-contained', 'false')
}
else {
$publishArgs += @('--self-contained', 'true', '-p:PublishSingleFile=true', '-p:IncludeNativeLibrariesForSelfExtract=true', '-p:EnableCompressionInSingleFile=true')
}
Write-Host "publishing ($(if ($FrameworkDependent) { 'requires .NET 9' } else { 'self-contained' }))..." -ForegroundColor Cyan
& dotnet @publishArgs | Where-Object { $_ -match 'error|warning CS|->' }
if ($LASTEXITCODE -ne 0) { throw "dotnet publish failed" }
Remove-Item (Join-Path $stage 'bin\*.pdb') -Force -ErrorAction SilentlyContinue
foreach ($f in 'install.ps1', 'uninstall.ps1', 'README.md', 'README.pl.md', 'CHANGELOG.md', 'LICENSE') {
Copy-Item (Join-Path $PSScriptRoot $f) $stage -Force
}
$size = [math]::Round((Get-ChildItem $stage -Recurse -File | Measure-Object Length -Sum).Sum / 1MB, 1)
Write-Host "package: $stage ($size MB)" -ForegroundColor Cyan
if (-not $NoZip) {
$version = ([xml](Get-Content $proj -Raw)).Project.PropertyGroup.Version | Where-Object { $_ } | Select-Object -First 1
if (-not $version) { $version = Get-Date -Format 'yyyyMMdd' }
$zip = Join-Path $OutDir "xpp-lens-$version.zip"
if (Test-Path $zip) { Remove-Item $zip -Force }
# Entries with '/' as the ZIP format requires (Compress-Archive in Windows PowerShell 5.1 writes '\').
Add-Type -AssemblyName System.IO.Compression, System.IO.Compression.FileSystem
$archive = [IO.Compression.ZipFile]::Open($zip, [IO.Compression.ZipArchiveMode]::Create)
try {
$root = Split-Path $stage -Parent
foreach ($file in Get-ChildItem $stage -Recurse -File) {
$entry = $file.FullName.Substring($root.Length + 1).Replace('\', '/')
[void][IO.Compression.ZipFileExtensions]::CreateEntryFromFile($archive, $file.FullName, $entry, [IO.Compression.CompressionLevel]::Optimal)
}
}
finally {
$archive.Dispose()
}
Write-Host "zip: $zip ($([math]::Round((Get-Item $zip).Length / 1MB, 1)) MB)" -ForegroundColor Cyan
}
Write-Host "`nOn the target machine: unzip and run install.ps1" -ForegroundColor Green