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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# When using System.IO.Compression.ZipFile.CreateFromDirectory in PowerShell, it still uses backslashes in the zip paths
# despite this https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/mitigation-ziparchiveentry-fullname-path-separator
# Based upon post by Seth Jackson https://sethjackson.github.io/2016/12/17/path-separators/
#
# PowerShell 5 (WMF5) & 6
# Using class Keyword https://msdn.microsoft.com/powershell/reference/5.1/Microsoft.PowerShell.Core/about/about_Classes
#
# https://gist.github.com/lantrix/738ebfa616d5222a8b1db947793bc3fc
#
####################################
### Fix Zip slash ###
####################################
Add-Type -AssemblyName System.Text.Encoding
Add-Type -AssemblyName System.IO.Compression.FileSystem
class FixedEncoder : System.Text.UTF8Encoding {
FixedEncoder() : base($true) { }
[byte[]] GetBytes([string] $s)
{
$s = $s.Replace("\", "/");
return ([System.Text.UTF8Encoding]$this).GetBytes($s);
}
}
####################################
### Configuration ###
####################################
$enableMSI = $false
# Profilling
$stopWatch = New-Object -TypeName System.Diagnostics.Stopwatch
$deployStopWatch = New-Object -TypeName System.Diagnostics.Stopwatch
$stopWatch.Start()
# Script working directory
Set-Location $PSScriptRoot
# Variables
$software = "UVtools"
$project = "UVtools.WPF"
$buildWith = "Release"
$netFolder = "net5.0"
$releaseFolder = "$PSScriptRoot\$project\bin\$buildWith\$netFolder"
$publishFolder = "$PSScriptRoot\publish"
#$version = (Get-Command "$releaseFolder\UVtools.dll").FileVersionInfo.ProductVersion
$projectXml = [Xml] (Get-Content "$PSScriptRoot\$project\$project.csproj")
$version = "$($projectXml.Project.PropertyGroup.Version)".Trim();
if([string]::IsNullOrWhiteSpace($version)){
Write-Error "Can not detect the UVtools version, does $project\$project.csproj exists?"
exit
}
# MSI Variables
$installers = @("UVtools.InstallerMM", "UVtools.Installer")
$msiSourceFile = "$PSScriptRoot\UVtools.Installer\bin\Release\UVtools.msi"
$msbuild = "`"${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe`" /t:Build /p:Configuration=$buildWith /p:MSIProductVersion=$version"
Write-Output "
####################################
### UVtools builder & deployer ###
####################################
Version: $version [$buildWith]
"
####################################
### Clean up previous publish ###
####################################
# Clean up previous publish
Remove-Item $publishFolder -Recurse -ErrorAction Ignore # Clean
####################################
### Self-contained runtimes ###
####################################
$runtimes =
@{
"win-x64" = @{
"extraCmd" = "-p:PublishReadyToRun=true"
"exclude" = @("libcvextern.so", "libcvextern.dylib", "UVtools.sh")
}
"linux-x64" = @{
"extraCmd" = "-p:PublishReadyToRun=true"
"exclude" = @("x86", "x64", "libcvextern.dylib")
}
"rhel-x64" = @{
"extraCmd" = "-p:PublishReadyToRun=true"
"exclude" = @("x86", "x64", "libcvextern.dylib")
}
#"unix-x64" = @{
# "extraCmd" = "-p:PublishReadyToRun=true"
# "exclude" = @("x86", "x64", "libcvextern.dylib")
#}
"osx-x64" = @{
"extraCmd" = "-p:PublishReadyToRun=true"
"exclude" = @("x86", "x64", "libcvextern.so")
}
}
foreach ($obj in $runtimes.GetEnumerator()) {
# Configuration
$deployStopWatch.Restart()
$runtime = $obj.Name; # runtime name
$extraCmd = $obj.extraCmd; # extra cmd to run with dotnet
$targetZip = "$publishFolder\${software}_${runtime}_v$version.zip" # Target zip filename
# Deploy
Write-Output "################################
Building: $runtime"
dotnet publish $project -o "$publishFolder\$runtime" -c $buildWith -r $runtime $extraCmd
# Cleanup
Remove-Item "$releaseFolder\$runtime" -Recurse -ErrorAction Ignore
foreach ($excludeObj in $obj.Value.exclude) {
Write-Output "Excluding: $excludeObj"
Remove-Item "$publishFolder\$runtime\$excludeObj" -Recurse -ErrorAction Ignore
}
# Zip
Write-Output "Compressing $runtime to: $targetZip"
[System.IO.Compression.ZipFile]::CreateFromDirectory("$publishFolder\$runtime", $targetZip, [System.IO.Compression.CompressionLevel]::Optimal, $false, [FixedEncoder]::new())
$deployStopWatch.Stop()
Write-Output "Took: $($deployStopWatch.Elapsed)
################################
"
}
# Universal package
$deployStopWatch.Restart()
$runtime = "universal-x86-x64"
$targetZip = "$publishFolder\${software}_${runtime}_v$version.zip"
Write-Output "################################
Building: $runtime"
dotnet build $project -c $buildWith
Write-Output "Compressing $runtime to: $targetZip"
[System.IO.Compression.ZipFile]::CreateFromDirectory($releaseFolder, $targetZip, [System.IO.Compression.CompressionLevel]::Optimal, $false, [FixedEncoder]::new())
Write-Output "Took: $($deployStopWatch.Elapsed)
################################
"
$stopWatch.Stop()
# MSI Installer for Windows
if($enableMSI)
{
$deployStopWatch.Restart()
$runtime = 'win-x64'
$msiTargetFile = "$publishFolder\${software}_${runtime}_v$version.msi"
Write-Output "################################
Building: $runtime MSI Installer"
foreach($installer in $installers)
{
# Clean and build MSI
Remove-Item "$PSScriptRoot\$installer\obj" -Recurse -ErrorAction Ignore
Remove-Item "$PSScriptRoot\$installer\bin" -Recurse -ErrorAction Ignore
iex "& $msbuild $installer\$installer.wixproj"
}
Write-Output "Coping $runtime MSI to: $msiTargetFile"
Copy-Item $msiSourceFile $msiTargetFile
Write-Output "Took: $($deployStopWatch.Elapsed)
################################
"
}
Write-Output "
####################################
### Completed ###
####################################
In: $($stopWatch.Elapsed)"
|