forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
204 lines (165 loc) · 6.47 KB
/
build.cake
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// examples
/*
./build.ps1 -Target NugetPack
./build.ps1 -Target NugetPack -ScriptArgs '-packageVersion="9.9.9-custom"'
*/
//////////////////////////////////////////////////////////////////////
// ADDINS
//////////////////////////////////////////////////////////////////////
#addin "nuget:?package=Cake.Xamarin&version=3.0.0"
#addin "nuget:?package=Cake.Android.Adb&version=3.0.0"
#addin "nuget:?package=Cake.Git&version=0.19.0"
//////////////////////////////////////////////////////////////////////
// TOOLS
//////////////////////////////////////////////////////////////////////
#tool nuget:?package=NUnit.ConsoleRunner&version=3.4.0
#tool nuget:?package=GitVersion.CommandLine&version=4.0.0
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Debug");
var gitVersion = GitVersion();
var majorMinorPatch = gitVersion.MajorMinorPatch;
var informationalVersion = gitVersion.InformationalVersion;
var buildVersion = gitVersion.FullBuildMetaData;
var nugetversion = Argument<string>("packageVersion", gitVersion.NuGetVersion);
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectories("./**/obj", (fsi)=> !fsi.Path.FullPath.Contains("XFCorePostProcessor") && !fsi.Path.FullPath.StartsWith("tools"));
CleanDirectories("./**/bin", (fsi)=> !fsi.Path.FullPath.Contains("XFCorePostProcessor") && !fsi.Path.FullPath.StartsWith("tools"));
});
Task("NuGetPack")
.IsDependentOn("Build")
.IsDependentOn("_NuGetPack");
Task("_NuGetPack")
.Does(() =>
{
Information("Nuget Version: {0}", nugetversion);
var nugetPackageDir = Directory("./artifacts");
var nuGetPackSettings = new NuGetPackSettings
{
OutputDirectory = nugetPackageDir,
Version = nugetversion
};
var nugetFilePaths =
GetFiles("./.nuspec/*.nuspec");
nuGetPackSettings.Properties.Add("configuration", configuration);
nuGetPackSettings.Properties.Add("platform", "anycpu");
// nuGetPackSettings.Verbosity = NuGetVerbosity.Detailed;
NuGetPack(nugetFilePaths, nuGetPackSettings);
});
Task("Restore")
.Does(() =>
{
try{
MSBuild("./Xamarin.Forms.sln", GetMSBuildSettings().WithTarget("restore"));
}
catch{
// ignore restore errors that come from uwp
if(IsRunningOnWindows())
throw;
}
});
Task("BuildHack")
.IsDependentOn("Restore")
.Does(() =>
{
if(!IsRunningOnWindows())
{
MSBuild("./Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj", GetMSBuildSettings().WithRestore());
}
});
Task("Build")
.IsDependentOn("Restore")
.IsDependentOn("BuildHack")
.IsDependentOn("Android81")
.Does(() =>
{
try{
MSBuild("./Xamarin.Forms.sln", GetMSBuildSettings().WithRestore());
}
catch(Exception)
{
if(IsRunningOnWindows())
throw;
}
});
Task("Android81")
.IsDependentOn("BuildHack")
.Does(() =>
{
string[] androidProjects =
new []
{
"./Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj",
"./Xamarin.Forms.Platform.Android.AppLinks/Xamarin.Forms.Platform.Android.AppLinks.csproj",
"./Xamarin.Forms.Maps.Android/Xamarin.Forms.Maps.Android.csproj",
"./Stubs/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android (Forwarders).csproj"
};
foreach(var project in androidProjects)
MSBuild(project,
GetMSBuildSettings()
.WithRestore()
.WithProperty("AndroidTargetFrameworkVersion", "v8.1"));
});
Task("VSMAC")
.IsDependentOn("BuildHack")
.Does(() =>
{
MSBuild("./Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj",
GetMSBuildSettings()
.WithRestore()
// work around bug on vs mac where resources generate wrong first time
.WithTarget("rebuild")
);
StartProcess("open", new ProcessSettings{ Arguments = "Xamarin.Forms.sln" });
});
/*
Task("Deploy")
.IsDependentOn("DeployiOS")
.IsDependentOn("DeployAndroid");
// TODO? Not sure how to make this work
Task("DeployiOS")
.Does(() =>
{
// not sure how to get this to deploy to iOS
BuildiOSIpa("./Xamarin.Forms.sln", platform:"iPhoneSimulator", configuration:"Debug");
});
*/
Task("DeployAndroid")
.IsDependentOn("BuildHack")
.Does(() =>
{
MSBuild("./Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj", GetMSBuildSettings().WithRestore());
MSBuild("./Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj", GetMSBuildSettings().WithRestore());
BuildAndroidApk("./Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj", sign:true, configuration:configuration);
AdbUninstall("AndroidControlGallery.AndroidControlGallery");
AdbInstall("./Xamarin.Forms.ControlGallery.Android/bin/Debug/AndroidControlGallery.AndroidControlGallery-Signed.apk");
AmStartActivity("AndroidControlGallery.AndroidControlGallery/md546303760447087909496d02dc7b17ae8.Activity1");
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Build")
;
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);
MSBuildSettings GetMSBuildSettings()
{
var msbuildSettings = new MSBuildSettings();
msbuildSettings.PlatformTarget = PlatformTarget.MSIL;
msbuildSettings.MSBuildPlatform = (Cake.Common.Tools.MSBuild.MSBuildPlatform)1;
msbuildSettings.Configuration = configuration;
return msbuildSettings;
}