forked from HMBSbige/ShadowsocksR-Windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
119 lines (89 loc) · 3.39 KB
/
build.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
107
108
109
110
111
112
113
114
115
116
117
118
119
# REM The reason we don't use dotnet build is that dotnet build doesn't support COM references yet https://github.com/microsoft/msbuild/issues/3986
param([string]$buildtfm = 'all')
Write-Host 'dotnet SDK version'
dotnet --version
$exe = 'ShadowsocksR.exe'
$net_tfm = 'net48'
$netcore_tfm = 'netcoreapp3.1'
$configuration = 'Release'
$mainDir = (Get-Item -Path ".\").FullName
$net_baseoutput = "$mainDir\shadowsocks-csharp\bin\$configuration"
$apphostpatcher_dir = "$mainDir\AppHostPatcher"
Write-Host $mainDir
Write-Host $net_baseoutput
Write-Host $apphostpatcher_dir
$buildNet = $buildtfm -eq 'all' -or $buildtfm -eq 'net'
$buildCore = $buildtfm -eq 'all' -or $buildtfm -eq 'core'
$buildCoreX86 = $buildtfm -eq 'all' -or $buildtfm -eq 'core-x86'
$buildCoreX64 = $buildtfm -eq 'all' -or $buildtfm -eq 'core-x64'
function Build-AppHostPatcher
{
Write-Host Building AppHostPatcher
$outdir = "$apphostpatcher_dir\bin\$configuration\$netcore_tfm"
$publishDir = "$outdir\publish"
Remove-Item $publishDir -Recurse -Force -Confirm:$false -ErrorAction Ignore
msbuild -v:m -m -r -t:Publish -p:Configuration=$configuration -p:TargetFramework=$netcore_tfm
if ($LASTEXITCODE) { cd $mainDir ; exit $LASTEXITCODE }
}
function Build-NetFramework
{
Write-Host 'Building .NET Framework x86 and x64'
$outdir = "$net_baseoutput\$net_tfm"
msbuild -v:m -m -r -t:Build -p:Configuration=$configuration -p:TargetFramework=$net_tfm
if ($LASTEXITCODE) { cd $mainDir ; exit $LASTEXITCODE }
}
function Build-NetCore
{
Write-Host 'Building .NET Core'
$outdir = "$net_baseoutput\$netcore_tfm"
$publishDir = "$outdir\publish"
Remove-Item $publishDir -Recurse -Force -Confirm:$false -ErrorAction Ignore
msbuild -v:m -m -r -t:Publish -p:Configuration=$configuration -p:TargetFramework=$netcore_tfm
if ($LASTEXITCODE) { cd $mainDir ; exit $LASTEXITCODE }
$tmpbin = 'tmpbin'
Rename-Item $publishDir $tmpbin
New-Item -ItemType Directory $publishDir > $null
Move-Item $outdir\$tmpbin $publishDir
Rename-Item $publishDir\$tmpbin bin
Move-Item $publishDir\bin\$exe $publishDir
& $apphostpatcher_dir\bin\$configuration\$netcore_tfm\AppHostPatcher.exe $publishDir\$exe -d bin
if ($LASTEXITCODE) { cd $mainDir ; exit $LASTEXITCODE }
}
function Build-NetCoreSelfContained
{
param([string]$arch)
Write-Host "Building .NET Core $arch"
$rid = "win-$arch"
$outdir = "$net_baseoutput\$netcore_tfm\$rid"
$publishDir = "$outdir\publish"
Remove-Item $publishDir -Recurse -Force -Confirm:$false -ErrorAction Ignore
msbuild -v:m -m -r -t:Publish -p:Configuration=$configuration -p:TargetFramework=$netcore_tfm -p:RuntimeIdentifier=$rid -p:SelfContained=True -p:PublishReadyToRun=True
if ($LASTEXITCODE) { cd $mainDir ; exit $LASTEXITCODE }
$tmpbin = 'tmpbin'
Rename-Item $publishDir $tmpbin
New-Item -ItemType Directory $publishDir > $null
Move-Item $outdir\$tmpbin $publishDir
Rename-Item $publishDir\$tmpbin bin
Move-Item $publishDir\bin\$exe $publishDir
& $apphostpatcher_dir\bin\$configuration\$netcore_tfm\AppHostPatcher.exe $publishDir\$exe -d bin
if ($LASTEXITCODE) { cd $mainDir ; exit $LASTEXITCODE }
}
if ($buildCore -or $buildCoreX86 -or $buildCoreX64)
{
cd $apphostpatcher_dir
Build-AppHostPatcher
}
cd $mainDir\shadowsocks-csharp
if ($buildNet) {
Build-NetFramework
}
if ($buildCore) {
Build-NetCore
}
if ($buildCoreX86) {
Build-NetCoreSelfContained x86
}
if ($buildCoreX64) {
Build-NetCoreSelfContained x64
}
cd $mainDir