forked from vpnhood/VpnHood
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PublishApp.ps1
106 lines (89 loc) · 3.89 KB
/
PublishApp.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
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
param(
[Parameter(Mandatory=$true)] [String]$projectDir,
[String]$packageName,
[String]$packagesDir=$null,
[String]$updateUrl=$null,
[String]$packageDownloadUrl=$null,
[Switch]$withLauncher=$false)
# Info
Write-Host;
Write-Host "*** Building $packageName..." -BackgroundColor Yellow -ForegroundColor Black;
# Common
. "$PSScriptRoot\Common.ps1"
# paths
$projectFile = (Get-ChildItem -path $projectDir -file -Filter "*.csproj").FullName;
$assemblyName = ([Xml] (Get-Content $projectFile)).Project.PropertyGroup.AssemblyName;
$targetFramework = ([Xml] (Get-Content $projectFile)).Project.PropertyGroup.TargetFramework;
$packageId = ([Xml] (Get-Content $projectFile)).Project.PropertyGroup.PackageId;
$packageId = "$packageId".Trim();
$publishDir = Join-Path $projectDir "bin/release/publish";
$publishPackDir = Join-Path $projectDir "bin/release/publish-pack";
#clean publish directory
$_ = New-Item -ItemType Directory -Force -Path $publishDir;
Remove-Item "$publishDir/*" -ErrorAction Ignore -Recurse;
#update project version
UpdateProjectVersion $projectFile;
# Prepate AppHotUpdate
$outDir = $publishDir;
if ($withLauncher)
{
$outDir = Join-Path $publishDir $versionParam;
$publishInfoFile = Join-Path $publishDir "publish.json";
$app_publishFile = Join-Path $publishDir "app_publish.txt";
$launcherProjectDir = Join-Path $solutionDir "VpnHood.App.Launcher";
# find launchFileName
if ([string]::IsNullOrWhiteSpace($assemblyName))
{
Throw "Could not retrieve AssemblyName from the project!";
}
$assemblyName = ([string]$assemblyName).Trim();
$launchFileName="$assemblyName.dll";
# write publish info
$json = @{
Version=$versionParam;
LaunchPath=$versionParam + "/$launchFileName";
TargetFramework="$targetFramework".Trim();
UpdateUrl=$updateUrl;
PackageDownloadUrl=$packageDownloadUrl;
PackageFileName="$packageName.zip";
};
$json | ConvertTo-Json -depth 100 | Out-File $publishInfoFile -Encoding utf8;
# Create launcher
Write-Host;
Write-Host "*** Creating Launcher..." -BackgroundColor Blue -ForegroundColor White;
UpdateProjectVersion (Join-Path $launcherProjectDir "VpnHood.App.Launcher.csproj");
dotnet publish "$launcherProjectDir" -c "Release" --output "$publishDir\launcher" --framework net6.0 --no-self-contained /p:Version=$versionParam;
if ($withVbsLauncher)
{
Copy-Item -path "$PSScriptRoot\run.vbs" -Destination "$publishDir\" -force
}
}
# publish
Write-Host;
Write-Host "*** Publishing $packageId..." -BackgroundColor Blue -ForegroundColor White;
if (-not $noclean) { dotnet clean "$projectDir" -c "Release" --output $outDir }
dotnet publish "$projectDir" -c "Release" --output $outDir --framework $targetFramework --no-self-contained /p:Version=$versionParam
if ($LASTEXITCODE -gt 0) { Throw "The publish exited with error code: " + $lastexitcode; }
# create zip package and zip updater
if ($withLauncher)
{
$publishPackFilePath = Join-Path $publishPackDir "$packageName.zip";
$publishPackFilePathTar = Join-Path $publishPackDir "$packageName.tar.gz";
$publishPackInfoFilePath = Join-Path $publishPackDir "$packageName.json";
Write-Host;
Write-Host "*** Packing (ZIP) $publishPackFilePath..." -BackgroundColor Blue -ForegroundColor White;
New-Item -ItemType Directory -Force -Path $publishPackDir
Remove-Item "$publishPackDir\*" -ErrorAction Ignore -Recurse;
Compress-Archive -Path "$publishDir\*" -DestinationPath $publishPackFilePath;
tar -czvf $publishPackFilePathTar -C "$publishDir\" *
$json | ConvertTo-Json -depth 100 | Out-File $publishPackInfoFilePath -Encoding utf8;
#####
# copy to solution output
if ($packagesDir)
{
New-Item -ItemType Directory -Path $packagesDir -Force
Copy-Item -path "$publishPackDir\*" -Destination "$packagesDir\" -Force
}
}
# ReportVersion
ReportVersion