-
Notifications
You must be signed in to change notification settings - Fork 174
/
Copy pathBuild.ps1
174 lines (142 loc) · 4.32 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
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
param([Switch]$Rebuild)
[string]$msbuild = "msbuild"
if ( $env:APPVEYOR -eq "True" )
{
# AppVeyor should have right MSBuild and dotnet-cli...
# Android SDK should be installed in init and ANDROID_HOME should be initialized before this script.
}
else
{
[string]$VSMSBuildExtensionsPath = $null
$msbuildCandidates = @(
"${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\MSBuild.exe",
"${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\MSBuild.exe",
"${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\bin\MSBuild.exe",
"${env:ProgramFiles}\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\MSBuild.exe",
"${env:ProgramFiles}\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\MSBuild.exe",
"${env:ProgramFiles}\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\bin\MSBuild.exe"
)
foreach ( $msbuildCandidate in $msbuildCandidates )
{
if ( ( Test-Path $msbuildCandidate ) )
{
$VSMSBuildExtensionsPath = [IO.Path]::GetFullPath( [IO.Path]::GetDirectoryName( $msbuildCandidate ) + "\..\..\" )
break;
}
}
if ( $VSMSBuildExtensionsPath -eq $null )
{
Write-Error "Failed to locate MSBuild.exe which can build .NET Core and .NET 3.5. VS2017 is required."
exit 1
}
./SetBuildEnv.ps1
}
[string]$buildConfig = 'Release'
if ( ![String]::IsNullOrWhitespace( $env:CONFIGURATION ) )
{
$buildConfig = $env:CONFIGURATION
}
[string]$sln = '../MsgPack.sln'
[string]$slnCompat = '../MsgPack.compats.sln'
[string]$slnWindows = '../MsgPack.Windows.sln'
[string]$slnXamarin = '../MsgPack.Xamarin.sln'
$buildOptions = @( '/v:minimal' )
if( $Rebuild )
{
$buildOptions += '/t:Rebuild'
}
$buildOptions += "/p:Configuration=${buildConfig}"
$restoreOptions = "/v:minimal"
Write-Host "Clean up directories..."
# Unity
if ( !( Test-Path "./MsgPack-CLI" ) )
{
New-Item ./MsgPack-CLI -Type Directory | Out-Null
}
else
{
Remove-Item ./MsgPack-CLI/* -Recurse -Force
}
if ( !( Test-Path "../dist" ) )
{
New-Item ../dist -Type Directory | Out-Null
}
else
{
Remove-Item ../dist/* -Recurse -Force
}
if ( ( Test-Path "../bin/Xamarin.iOS10" ) )
{
Remove-Item ../bin/Xamarin.iOS10 -Recurse
}
if ( !( Test-Path "./MsgPack-CLI/mpu" ) )
{
New-Item ./MsgPack-CLI/mpu -Type Directory | Out-Null
}
# build
Write-Host "Restore $sln packages..."
& $msbuild /t:restore $sln $restoreOptions
if ( $LastExitCode -ne 0 )
{
Write-Error "Failed to restore $sln"
exit $LastExitCode
}
Write-Host "Build $sln..."
& $msbuild $sln $buildOptions
if ( $LastExitCode -ne 0 )
{
Write-Error "Failed to build $sln"
exit $LastExitCode
}
Write-Host "Restore $slnCompat packages..."
& $msbuild /t:restore $slnCompat $restoreOptions
if ( $LastExitCode -ne 0 )
{
Write-Error "Failed to restore $slnCompat"
exit $LastExitCode
}
Write-Host "Build $slnCompat..."
& $msbuild $slnCompat $buildOptions
if ( $LastExitCode -ne 0 )
{
Write-Error "Failed to build $slnCompat"
exit $LastExitCode
}
Write-Host "Restore $slnWindows packages..."
if ( $env:APPVEYOR -eq "True" )
{
# Use nuget for legacy environments.
nuget restore $slnWindows -Verbosity quiet
}
else
{
& $msbuild /t:restore $slnWindows $restoreOptions
}
if ( $LastExitCode -ne 0 )
{
Write-Error "Failed to restore $slnWindows"
exit $LastExitCode
}
Write-Host "Build $slnWindows..."
& $msbuild $slnWindows $buildOptions
if ( $LastExitCode -ne 0 )
{
Write-Error "Failed to build $slnWindows"
exit $LastExitCode
}
if ( $buildConfig -eq 'Release' )
{
Write-Host "Build NuGet packages..."
& $msbuild ../src/MsgPack/MsgPack.csproj /t:pack /v:minimal /p:Configuration=$buildConfig /p:IncludeSource=true /p:IncludeSymbols=true /p:NuspecProperties=version=$env:PackageVersion
Move-Item ../bin/*.nupkg ../dist/
Copy-Item ../bin/* ./MsgPack-CLI/ -Recurse -Exclude @("*.vshost.*")
Copy-Item ../tools/mpu/bin/* ./MsgPack-CLI/mpu/ -Recurse -Exclude @("*.vshost.*")
[Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" ) | Out-Null
# 'latest' should be rewritten with semver manually.
if ( ( Test-Path "../dist/MsgPack.Cli.${env:PackageVersion}.zip" ) )
{
Remove-Item ../dist/MsgPack.Cli.${env:PackageVersion}.zip
}
[IO.Compression.ZipFile]::CreateFromDirectory( ( Convert-Path './MsgPack-CLI' ), ( Convert-Path '../dist/' ) + "MsgPack.Cli.${env:PackageVersion}.zip" )
Remove-Item ./MsgPack-CLI -Recurse -Force
}