Skip to content

Commit ba14fa0

Browse files
committed
Fix build script
This commit migrates preview dotnet to latest msbuild. Note that this script depends on Visual Studio 2017 because dotnet CLI does not support .NET 3.5 and Xamarin yet. In addition this script assumes that build env has path to latest msbuild since it is hard to determine the path of msbuild due to it contains Visual Studio edition.
1 parent dee86c6 commit ba14fa0

File tree

1 file changed

+36
-78
lines changed

1 file changed

+36
-78
lines changed

build/Build.ps1

Lines changed: 36 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
11
param([Switch]$Rebuild)
22

3+
[string]$msbuild = "msbuild"
4+
35
if ( $env:APPVEYOR -eq "True" )
46
{
5-
[string]$builder = "MSBuild.exe"
6-
[string]$winBuilder = "MSBuild.exe"
7-
[string]$nuget = "nuget"
8-
[string]$nugetVerbosity = "quiet"
9-
[string]$dotnetVerbosity = "Warning"
107

118
# AppVeyor should have right MSBuild and dotnet-cli...
129
# Android SDK should be installed in init and ANDROID_HOME should be initialized before this script.
1310
}
1411
else
1512
{
13+
[string]$VSMSBuildExtensionsPath = $null
14+
15+
$msbuildCandidates = @(
16+
"${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\MSBuild.exe",
17+
"${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\MSBuild.exe",
18+
"${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\bin\MSBuild.exe",
19+
"${env:ProgramFiles}\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\MSBuild.exe",
20+
"${env:ProgramFiles}\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\MSBuild.exe",
21+
"${env:ProgramFiles}\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\bin\MSBuild.exe"
22+
)
23+
foreach ( $msbuildCandidate in $msbuildCandidates )
24+
{
25+
if ( ( Test-Path $msbuildCandidate ) )
26+
{
27+
$VSMSBuildExtensionsPath = [IO.Path]::GetFullPath( [IO.Path]::GetDirectoryName( $msbuildCandidate ) + "\..\..\" )
28+
break;
29+
}
30+
}
31+
32+
if ( $VSMSBuildExtensionsPath -eq $null )
33+
{
34+
Write-Error "Failed to locate MSBuild.exe which can build .NET Core and .NET 3.5. VS2017 is required."
35+
exit 1
36+
}
37+
1638
# Ensure Android SDK for API level 10 is installed.
1739
# Thanks to https://github.com/googlesamples/android-ndk/pull/80
1840

@@ -29,27 +51,6 @@ else
2951
{
3052
./UpdateAndroidSdk.cmd
3153
}
32-
[string]$builder = "${env:ProgramFiles(x86)}\MSBuild\14.0\Bin\MSBuild.exe"
33-
[string]$winBuilder = "${env:ProgramFiles(x86)}\MSBuild\14.0\Bin\MSBuild.exe"
34-
[string]$nuget = "../.nuget/nuget.exe"
35-
[string]$nugetVerbosity = "normal"
36-
[string]$dotnetVerbosity = "Information"
37-
38-
if ( !( Test-Path( "$winBuilder" ) ) )
39-
{
40-
$winBuilder = "${env:ProgramFiles}\MSBuild\14.0\Bin\MSBuild.exe"
41-
}
42-
if ( !( Test-Path( "$winBuilder" ) ) )
43-
{
44-
Write-Error "MSBuild v14 is required."
45-
exit 1
46-
}
47-
48-
if ( !( Test-Path( "${env:ProgramFiles}\dotnet\dotnet.exe" ) ) )
49-
{
50-
Write-Error "DotNet CLI is required."
51-
exit 1
52-
}
5354
}
5455

5556
[string]$buildConfig = 'Release'
@@ -62,7 +63,6 @@ if ( ![String]::IsNullOrWhitespace( $env:CONFIGURATION ) )
6263
[string]$slnCompat = '../MsgPack.compats.sln'
6364
[string]$slnWindows = '../MsgPack.Windows.sln'
6465
[string]$slnXamarin = '../MsgPack.Xamarin.sln'
65-
[string]$projCoreClr = "../src/Msgpack.CoreClr"
6666

6767
$buildOptions = @( '/v:minimal' )
6868
if( $Rebuild )
@@ -71,6 +71,7 @@ if( $Rebuild )
7171
}
7272

7373
$buildOptions += "/p:Configuration=${buildConfig}"
74+
$restoreOptions = "/v:minimal"
7475

7576
# Unity
7677
if ( !( Test-Path "./MsgPack-CLI" ) )
@@ -102,96 +103,53 @@ if ( !( Test-Path "./MsgPack-CLI/mpu" ) )
102103
}
103104

104105
# build
105-
& $nuget restore $sln -Verbosity $nugetVerbosity
106+
& $msbuild /t:restore $sln $restoreOptions
106107
if ( $LastExitCode -ne 0 )
107108
{
108109
Write-Error "Failed to restore $sln"
109110
exit $LastExitCode
110111
}
111112

112-
& $builder $sln $buildOptions
113+
& $msbuild $sln $buildOptions
113114
if ( $LastExitCode -ne 0 )
114115
{
115116
Write-Error "Failed to build $sln"
116117
exit $LastExitCode
117118
}
118119

119-
& $nuget restore $slnCompat -Verbosity $nugetVerbosity
120+
& $msbuild /t:restore $slnCompat $restoreOptions
120121
if ( $LastExitCode -ne 0 )
121122
{
122123
Write-Error "Failed to restore $slnCompat"
123124
exit $LastExitCode
124125
}
125126

126-
& $builder $slnCompat $buildOptions
127+
& $msbuild $slnCompat $buildOptions
127128
if ( $LastExitCode -ne 0 )
128129
{
129130
Write-Error "Failed to build $slnCompat"
130131
exit $LastExitCode
131132
}
132133

133-
& $nuget restore $slnWindows -Verbosity $nugetVerbosity
134+
& $msbuild /t:restore $slnWindows $restoreOptions
134135
if ( $LastExitCode -ne 0 )
135136
{
136137
Write-Error "Failed to restore $slnWindows"
137138
exit $LastExitCode
138139
}
139140

140-
& $winBuilder $slnWindows $buildOptions
141+
& $msbuild $slnWindows $buildOptions
141142
if ( $LastExitCode -ne 0 )
142143
{
143144
Write-Error "Failed to build $slnWindows"
144145
exit $LastExitCode
145146
}
146147

147-
& $nuget restore $slnXamarin -Verbosity $nugetVerbosity
148-
if ( $LastExitCode -ne 0 )
149-
{
150-
Write-Error "Failed to restore $slnXamarin"
151-
exit $LastExitCode
152-
}
153-
154-
& $builder $slnXamarin $buildOptions
155-
if ( $LastExitCode -ne 0 )
156-
{
157-
Write-Error "Failed to build $slnXamarin"
158-
exit $LastExitCode
159-
}
160-
161-
dotnet restore $projCoreClr
162-
if ( $LastExitCode -ne 0 )
163-
{
164-
Write-Error "Failed to restore $projNetStandard11"
165-
exit $LastExitCode
166-
}
167-
168-
$netstandardBaseCommandLine = @("build", "$projCoreClr", "-c", "$buildConfig")
169-
$netstandard1_1CommandLine = $netstandardBaseCommandLine + @("-f", "netstandard1.1")
170-
$netstandard1_3CommandLine = $netstandardBaseCommandLine + @("-f", "netstandard1.3")
171-
if ( $buildConfig -eq 'Release' )
172-
{
173-
$netstandard1_1CommandLine += @("-o", "../bin/netstandard1.1")
174-
$netstandard1_3CommandLine += @("-o", "../bin/netstandard1.3")
175-
}
176-
177-
& "dotnet" $netstandard1_1CommandLine
178-
if ( $LastExitCode -ne 0 )
179-
{
180-
Write-Error "Failed to build netstd1.1. $netstandard1_1CommandLine"
181-
exit $LastExitCode
182-
}
183-
184-
& "dotnet" $netstandard1_3CommandLine
185-
if ( $LastExitCode -ne 0 )
186-
{
187-
Write-Error "Failed to build netstd1.3. $netstandard1_3CommandLine"
188-
exit $LastExitCode
189-
}
190-
191148
if ( $buildConfig -eq 'Release' )
192149
{
193-
& $nuget pack ../MsgPack.nuspec -Symbols -Version $env:PackageVersion -OutputDirectory ../dist
150+
& $msbuild ../src/MsgPack/MsgPack.csproj /t:pack /p:Configuration=$buildConfig /p:NuspecProperties=version=$env:PackageVersion
194151

152+
Move-Item ../bin/*.nupkg ../dist/
195153
Copy-Item ../bin/* ./MsgPack-CLI/ -Recurse -Exclude @("*.vshost.*")
196154
Copy-Item ../tools/mpu/bin/* ./MsgPack-CLI/mpu/ -Recurse -Exclude @("*.vshost.*")
197155
[Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" ) | Out-Null

0 commit comments

Comments
 (0)