forked from microsoft/appcenter-sdk-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.cake
More file actions
616 lines (544 loc) · 24.9 KB
/
build.cake
File metadata and controls
616 lines (544 loc) · 24.9 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
#tool nuget:?package=XamarinComponent
#addin nuget:?package=Cake.Xamarin
#addin nuget:?package=Cake.FileHelpers
#addin "Cake.AzureStorage"
#addin nuget:?package=Cake.Git
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
// MobileCenter module class definition.
class MobileCenterModule {
public string AndroidModule { get; set; }
public string IosModule { get; set; }
public string DotNetModule { get; set; }
public string NuGetVersion { get; set; }
public string PackageId { get; set; }
public string MainNuspecFilename { get; set; }
public string NuGetPackageName
{
get
{
return PackageId + "." + NuGetVersion + ".nupkg";
}
}
public string MacNuspecFilename
{
get { return "Mac" + MainNuspecFilename; }
}
public string WindowsNuspecFilename
{
get { return "Windows" + MainNuspecFilename; }
}
public MobileCenterModule(string android, string ios, string dotnet, string mainNuspecFilename) {
AndroidModule = android;
IosModule = ios;
DotNetModule = dotnet;
MainNuspecFilename = mainNuspecFilename;
}
}
// Prefix for temporary intermediates that are created by this script
var TEMPORARY_PREFIX = "CAKE_SCRIPT_TEMP";
var DOWNLOADED_ASSEMBLIES_FOLDER = TEMPORARY_PREFIX + "DownloadedAssemblies";
var MAC_ASSEMBLIES_ZIP = TEMPORARY_PREFIX + "MacAssemblies.zip";
var WINDOWS_ASSEMBLIES_ZIP = TEMPORARY_PREFIX + "WindowsAssemblies.zip";
// Assembly folders
var UWP_ASSEMBLIES_FOLDER = TEMPORARY_PREFIX + "UWPAssemblies";
var IOS_ASSEMBLIES_FOLDER = TEMPORARY_PREFIX + "iOSAssemblies";
var ANDROID_ASSEMBLIES_FOLDER = TEMPORARY_PREFIX + "AndroidAssemblies";
var PCL_ASSEMBLIES_FOLDER = TEMPORARY_PREFIX + "PCLAssemblies";
// Native SDK versions
var ANDROID_SDK_VERSION = "0.10.0";
var IOS_SDK_VERSION = "0.10.1";
var PLATFORM_PATHS = new PlatformPaths();
// URLs for downloading binaries.
/*
* Read this: http://www.mono-project.com/docs/faq/security/.
* On Windows,
* you have to do additional steps for SSL connection to download files.
* http://stackoverflow.com/questions/4926676/mono-webrequest-fails-with-https
* By running mozroots and install part of Mozilla's root certificates can make it work.
*/
var SDK_STORAGE_URL = "https://mobilecentersdkdev.blob.core.windows.net/sdk/";
var ANDROID_URL = SDK_STORAGE_URL + "MobileCenter-SDK-Android-" + ANDROID_SDK_VERSION + ".zip";
var IOS_URL = SDK_STORAGE_URL + "MobileCenter-SDK-iOS-" + IOS_SDK_VERSION + ".zip";
var MAC_ASSEMBLIES_URL = SDK_STORAGE_URL + MAC_ASSEMBLIES_ZIP;
var WINDOWS_ASSEMBLIES_URL = SDK_STORAGE_URL + WINDOWS_ASSEMBLIES_ZIP;
// Available MobileCenter modules.
var MOBILECENTER_MODULES = new [] {
new MobileCenterModule("mobile-center-release.aar", "MobileCenter.framework.zip", "SDK/MobileCenter/Microsoft.Azure.Mobile", "MobileCenter.nuspec"),
new MobileCenterModule("mobile-center-analytics-release.aar", "MobileCenterAnalytics.framework.zip", "SDK/MobileCenterAnalytics/Microsoft.Azure.Mobile.Analytics", "MobileCenterAnalytics.nuspec"),
new MobileCenterModule("mobile-center-crashes-release.aar", "MobileCenterCrashes.framework.zip", "SDK/MobileCenterCrashes/Microsoft.Azure.Mobile.Crashes", "MobileCenterCrashes.nuspec"),
new MobileCenterModule("mobile-center-distribute-release.aar", "MobileCenterDistribute.framework.zip", "SDK/MobileCenterDistribute/Microsoft.Azure.Mobile.Distribute", "MobileCenterDistribute.nuspec"),
new MobileCenterModule("mobile-center-push-release.aar", "MobileCenterPush.framework.zip", "SDK/MobileCenterPush/Microsoft.Azure.Mobile.Push", "MobileCenterPush.nuspec")
};
// Task TARGET for build
var TARGET = Argument("target", Argument("t", "Default"));
// Storage id to append to upload and download file names in storage
var STORAGE_ID = Argument("StorageId", Argument("storage-id", ""));
class AssemblyGroup
{
public string[] AssemblyPaths {get; set;}
public string AssemblyFolder {get; set;}
}
// This class contains the assembly folder paths and other platform dependent paths involved in preparing assemblies for VSTS and Azure storage.
// When a new platform is supported, an AssemblyGroup must be created and added to the proper {OS}UploadAssemblyGroups array. Also, its
// AssemblyFolder must be added to the correct platform's "DownloadAssemblyFolders" array.
class PlatformPaths
{
public PlatformPaths()
{
UploadAssemblyGroups = new List<AssemblyGroup>();
DownloadAssemblyFolders = new List<string>();
}
// Folders for the assemblies that the current platform must create and upload
public List<AssemblyGroup> UploadAssemblyGroups {get; set;}
// The name of the zip file to upload
public string UploadAssembliesZip {get; set;}
// The name of the zip file to download
public string DownloadAssembliesZip {get; set;}
// The paths of downloaded assembly folders
public List<string> DownloadAssemblyFolders {get; set;}
// The URL to download files from
public string DownloadUrl {get; set;}
}
// Prepare the platform paths for downloading, uploading, and preparing assemblies
Setup(context =>
{
if (IsRunningOnUnix())
{
var iosAssemblyGroup = new AssemblyGroup {
AssemblyFolder = IOS_ASSEMBLIES_FOLDER,
AssemblyPaths = new string[] { "SDK/MobileCenter/Microsoft.Azure.Mobile.iOS/bin/Release/Microsoft.Azure.Mobile.dll",
"SDK/MobileCenter/Microsoft.Azure.Mobile.iOS/bin/Release/Microsoft.Azure.Mobile.iOS.Bindings.dll",
"SDK/MobileCenterAnalytics/Microsoft.Azure.Mobile.Analytics.iOS/bin/Release/Microsoft.Azure.Mobile.Analytics.dll",
"SDK/MobileCenterAnalytics/Microsoft.Azure.Mobile.Analytics.iOS/bin/Release/Microsoft.Azure.Mobile.Analytics.iOS.Bindings.dll",
"SDK/MobileCenterCrashes/Microsoft.Azure.Mobile.Crashes.iOS/bin/Release/Microsoft.Azure.Mobile.Crashes.dll",
"SDK/MobileCenterCrashes/Microsoft.Azure.Mobile.Crashes.iOS/bin/Release/Microsoft.Azure.Mobile.Crashes.iOS.Bindings.dll",
"SDK/MobileCenterDistribute/Microsoft.Azure.Mobile.Distribute.iOS/bin/Release/Microsoft.Azure.Mobile.Distribute.dll",
"SDK/MobileCenterDistribute/Microsoft.Azure.Mobile.Distribute.iOS/bin/Release/Microsoft.Azure.Mobile.Distribute.iOS.Bindings.dll",
"SDK/MobileCenterPush/Microsoft.Azure.Mobile.Push.iOS/bin/Release/Microsoft.Azure.Mobile.Push.dll",
"SDK/MobileCenterPush/Microsoft.Azure.Mobile.Push.iOS.Bindings/bin/Release/Microsoft.Azure.Mobile.Push.iOS.Bindings.dll" }
};
var androidAssemblyGroup = new AssemblyGroup {
AssemblyFolder = ANDROID_ASSEMBLIES_FOLDER,
AssemblyPaths = new string[] { "SDK/MobileCenter/Microsoft.Azure.Mobile.Android/bin/Release/Microsoft.Azure.Mobile.dll",
"SDK/MobileCenter/Microsoft.Azure.Mobile.Android/bin/Release/Microsoft.Azure.Mobile.Android.Bindings.dll",
"SDK/MobileCenterAnalytics/Microsoft.Azure.Mobile.Analytics.Android/bin/Release/Microsoft.Azure.Mobile.Analytics.dll",
"SDK/MobileCenterAnalytics/Microsoft.Azure.Mobile.Analytics.Android/bin/Release/Microsoft.Azure.Mobile.Analytics.Android.Bindings.dll",
"SDK/MobileCenterCrashes/Microsoft.Azure.Mobile.Crashes.Android/bin/Release/Microsoft.Azure.Mobile.Crashes.dll",
"SDK/MobileCenterCrashes/Microsoft.Azure.Mobile.Crashes.Android/bin/Release/Microsoft.Azure.Mobile.Crashes.Android.Bindings.dll",
"SDK/MobileCenterDistribute/Microsoft.Azure.Mobile.Distribute.Android/bin/Release/Microsoft.Azure.Mobile.Distribute.dll",
"SDK/MobileCenterDistribute/Microsoft.Azure.Mobile.Distribute.Android/bin/Release/Microsoft.Azure.Mobile.Distribute.Android.Bindings.dll",
"SDK/MobileCenterPush/Microsoft.Azure.Mobile.Push.Android/bin/Release/Microsoft.Azure.Mobile.Push.dll",
"SDK/MobileCenterPush/Microsoft.Azure.Mobile.Push.Android.Bindings/bin/Release/Microsoft.Azure.Mobile.Push.Android.Bindings.dll" }
};
var pclAssemblyGroup = new AssemblyGroup {
AssemblyFolder = PCL_ASSEMBLIES_FOLDER,
AssemblyPaths = new string[] { "SDK/MobileCenter/Microsoft.Azure.Mobile/bin/Release/Microsoft.Azure.Mobile.dll",
"SDK/MobileCenterAnalytics/Microsoft.Azure.Mobile.Analytics/bin/Release/Microsoft.Azure.Mobile.Analytics.dll",
"SDK/MobileCenterCrashes/Microsoft.Azure.Mobile.Crashes/bin/Release/Microsoft.Azure.Mobile.Crashes.dll",
"SDK/MobileCenterDistribute/Microsoft.Azure.Mobile.Distribute/bin/Release/Microsoft.Azure.Mobile.Distribute.dll",
"SDK/MobileCenterPush/Microsoft.Azure.Mobile.Push/bin/Release/Microsoft.Azure.Mobile.Push.dll" }
};
PLATFORM_PATHS.UploadAssemblyGroups.Add(iosAssemblyGroup);
PLATFORM_PATHS.UploadAssemblyGroups.Add(androidAssemblyGroup);
PLATFORM_PATHS.UploadAssemblyGroups.Add(pclAssemblyGroup);
PLATFORM_PATHS.DownloadAssemblyFolders.Add(UWP_ASSEMBLIES_FOLDER);
PLATFORM_PATHS.DownloadAssemblyFolders.Add(UWP_ASSEMBLIES_FOLDER + "/x86");
PLATFORM_PATHS.DownloadAssemblyFolders.Add(UWP_ASSEMBLIES_FOLDER + "/x64");
PLATFORM_PATHS.DownloadAssemblyFolders.Add(UWP_ASSEMBLIES_FOLDER + "/ARM");
PLATFORM_PATHS.UploadAssembliesZip = MAC_ASSEMBLIES_ZIP + STORAGE_ID;
PLATFORM_PATHS.DownloadUrl = WINDOWS_ASSEMBLIES_URL + STORAGE_ID;
PLATFORM_PATHS.DownloadAssembliesZip = WINDOWS_ASSEMBLIES_ZIP + STORAGE_ID;
}
else
{
var uwpAnyCpuAssemblyGroup = new AssemblyGroup {
AssemblyFolder = UWP_ASSEMBLIES_FOLDER,
AssemblyPaths = new string[] { "nuget/Microsoft.Azure.Mobile.Crashes.targets",
"SDK/MobileCenter/Microsoft.Azure.Mobile.UWP/bin/Release/Microsoft.Azure.Mobile.dll",
"SDK/MobileCenterAnalytics/Microsoft.Azure.Mobile.Analytics.UWP/bin/Release/Microsoft.Azure.Mobile.Analytics.dll",
"SDK/MobileCenterCrashes/Microsoft.Azure.Mobile.Crashes.UWP/bin/Reference/Microsoft.Azure.Mobile.Crashes.dll",
"SDK/MobileCenterPush/Microsoft.Azure.Mobile.Push.UWP/bin/Release/Microsoft.Azure.Mobile.Push.dll" }
};
var uwpX86AssemblyGroup = new AssemblyGroup {
AssemblyFolder = UWP_ASSEMBLIES_FOLDER + "/x86",
AssemblyPaths = new string[] { "SDK/MobileCenterCrashes/Microsoft.Azure.Mobile.Crashes.UWP/bin/x86/Release/Microsoft.Azure.Mobile.Crashes.dll",
"Release/WatsonRegistrationUtility/WatsonRegistrationUtility.dll",
"Release/WatsonRegistrationUtility/WatsonRegistrationUtility.winmd" }
};
var uwpX64AssemblyGroup = new AssemblyGroup {
AssemblyFolder = UWP_ASSEMBLIES_FOLDER + "/x64",
AssemblyPaths = new string[] { "SDK/MobileCenterCrashes/Microsoft.Azure.Mobile.Crashes.UWP/bin/x64/Release/Microsoft.Azure.Mobile.Crashes.dll",
"x64/Release/WatsonRegistrationUtility/WatsonRegistrationUtility.dll",
"x64/Release/WatsonRegistrationUtility/WatsonRegistrationUtility.winmd" }
};
var uwpArmAssemblyGroup = new AssemblyGroup {
AssemblyFolder = UWP_ASSEMBLIES_FOLDER + "/ARM",
AssemblyPaths = new string[] { "SDK/MobileCenterCrashes/Microsoft.Azure.Mobile.Crashes.UWP/bin/ARM/Release/Microsoft.Azure.Mobile.Crashes.dll",
"ARM/Release/WatsonRegistrationUtility/WatsonRegistrationUtility.dll",
"ARM/Release/WatsonRegistrationUtility/WatsonRegistrationUtility.winmd" }
};
PLATFORM_PATHS.UploadAssemblyGroups.Add(uwpAnyCpuAssemblyGroup);
PLATFORM_PATHS.UploadAssemblyGroups.Add(uwpX86AssemblyGroup);
PLATFORM_PATHS.UploadAssemblyGroups.Add(uwpX64AssemblyGroup);
PLATFORM_PATHS.UploadAssemblyGroups.Add(uwpArmAssemblyGroup);
PLATFORM_PATHS.DownloadAssemblyFolders.Add(IOS_ASSEMBLIES_FOLDER);
PLATFORM_PATHS.DownloadAssemblyFolders.Add(ANDROID_ASSEMBLIES_FOLDER);
PLATFORM_PATHS.DownloadAssemblyFolders.Add(PCL_ASSEMBLIES_FOLDER);
PLATFORM_PATHS.UploadAssembliesZip = WINDOWS_ASSEMBLIES_ZIP + STORAGE_ID;
PLATFORM_PATHS.DownloadUrl = MAC_ASSEMBLIES_URL + STORAGE_ID;
PLATFORM_PATHS.DownloadAssembliesZip = MAC_ASSEMBLIES_ZIP + STORAGE_ID;
}
});
// Versioning task.
Task("Version")
.Does(() =>
{
var assemblyInfo = ParseAssemblyInfo("./" + "SDK/MobileCenter/Microsoft.Azure.Mobile/Properties/AssemblyInfo.cs");
var version = assemblyInfo.AssemblyInformationalVersion;
// Read AssemblyInfo.cs and extract versions for modules.
foreach (var module in MOBILECENTER_MODULES)
{
module.NuGetVersion = version;
}
});
// Package id task
Task("PackageId")
.Does(() =>
{
// Read AssemblyInfo.cs and extract package ids for modules.
foreach (var module in MOBILECENTER_MODULES)
{
var nuspecText = FileReadText("./nuget/" + module.MainNuspecFilename);
var startTag = "<id>";
var endTag = "</id>";
int startIndex = nuspecText.IndexOf(startTag) + startTag.Length;
int length = nuspecText.IndexOf(endTag) - startIndex;
var id = nuspecText.Substring(startIndex, length);
Information("id = " + id);
module.PackageId = id;
}
});
Task("Build").IsDependentOn("MacBuild").IsDependentOn("WindowsBuild");
Task("MacBuild")
.WithCriteria(() => IsRunningOnUnix())
.Does(() =>
{
// Run externals here instead of using dependency so that this doesn't get called on windows
RunTarget("Externals");
// Build solution
NuGetRestore("./MobileCenter-SDK-Build-Mac.sln");
MSBuild("./MobileCenter-SDK-Build-Mac.sln", c => c.Configuration = "Release");
}).OnError(HandleError);
// Building Windows code task
Task("WindowsBuild")
.WithCriteria(() => !IsRunningOnUnix())
.Does(() =>
{
// Build solution
NuGetRestore("./MobileCenter-SDK-Build-Windows.sln");
MSBuild("./MobileCenter-SDK-Build-Windows.sln", settings => settings.SetConfiguration("Release").WithProperty("Platform", "x86"));
MSBuild("./MobileCenter-SDK-Build-Windows.sln", settings => settings.SetConfiguration("Release").WithProperty("Platform", "x64"));
MSBuild("./MobileCenter-SDK-Build-Windows.sln", settings => settings.SetConfiguration("Release").WithProperty("Platform", "ARM"));
MSBuild("./MobileCenter-SDK-Build-Windows.sln", settings => settings.SetConfiguration("Release")); // any cpu
MSBuild("./MobileCenter-SDK-Build-Windows.sln", settings => settings.SetConfiguration("Reference")); // any cpu
}).OnError(HandleError);
Task("PrepareAssemblies").IsDependentOn("Build").Does(()=>
{
foreach (var assemblyGroup in PLATFORM_PATHS.UploadAssemblyGroups)
{
CopyFiles(assemblyGroup.AssemblyPaths, assemblyGroup.AssemblyFolder);
}
}).OnError(HandleError);
// Task dependencies for binding each platform.
Task("Bindings-Android").IsDependentOn("Externals-Android");
Task("Bindings-Ios").IsDependentOn("Externals-Ios");
// Downloading Android binaries.
Task("Externals-Android")
.Does(() =>
{
CleanDirectory("./externals/android");
// Download zip file.
DownloadFile(ANDROID_URL, "./externals/android/android.zip");
Unzip("./externals/android/android.zip", "./externals/android/");
// Copy files to {DotNetModule}.Android.Bindings/Jars
foreach (var module in MOBILECENTER_MODULES)
{
var files = GetFiles("./externals/android/*/" + module.AndroidModule);
CopyFiles(files, module.DotNetModule + ".Android.Bindings/Jars/");
}
}).OnError(HandleError);
// Downloading iOS binaries.
Task("Externals-Ios")
.Does(() =>
{
CleanDirectory("./externals/ios");
// Download zip file containing MobileCenter frameworks
DownloadFile(IOS_URL, "./externals/ios/ios.zip");
Unzip("./externals/ios/ios.zip", "./externals/ios/");
// Copy the MobileCenter binaries directly from the frameworks and add the ".a" extension
var files = GetFiles("./externals/ios/*/*.framework/MobileCenter*");
foreach (var file in files)
{
MoveFile(file, "./externals/ios/" + file.GetFilename() + ".a");
}
// Copy Distribute resource bundle and copy it to the externals directory. There is no method in cake to get all subdirectories.
if(DirectoryExists("./externals/ios/MobileCenter-SDK-iOS/MobileCenterDistributeResources.bundle"))
{
MoveDirectory("./externals/ios/MobileCenter-SDK-iOS/MobileCenterDistributeResources.bundle", "./externals/ios/MobileCenterDistributeResources.bundle");
}
}).OnError(HandleError);
// Create a common externals task depending on platform specific ones
Task("Externals").IsDependentOn("Externals-Ios").IsDependentOn("Externals-Android");
// Main Task.
Task("Default").IsDependentOn("NuGet").IsDependentOn("RemoveTemporaries");
// Build tests
Task("UITest").IsDependentOn("RestoreTestPackages").Does(() =>
{
MSBuild("./Tests/UITests/Contoso.Forms.Test.UITests.csproj", c => c.Configuration = "Release");
});
// Pack NuGets for appropriate platform
Task("NuGet")
.IsDependentOn("PrepareAssemblies")
.IsDependentOn("Version")
.Does(()=>
{
// NuGet on mac trims out the first ./ so adding it twice works around
var basePath = IsRunningOnUnix() ? (System.IO.Directory.GetCurrentDirectory().ToString() + @"/.") : "./";
CleanDirectory("output");
var specCopyName = TEMPORARY_PREFIX + "spec_copy.nuspec";
// Packaging NuGets.
foreach (var module in MOBILECENTER_MODULES)
{
var nuspecFilename = IsRunningOnUnix() ? module.MacNuspecFilename : module.WindowsNuspecFilename;
// Skipping not exists modules.
if (!FileExists("nuget/" + nuspecFilename))
{
continue;
}
// Prepare nuspec by making substitutions in a copied nuspec (to avoid altering the original)
CopyFile("nuget/" + nuspecFilename, specCopyName);
ReplaceTextInFiles(specCopyName, "$pcl_dir$", PCL_ASSEMBLIES_FOLDER);
ReplaceTextInFiles(specCopyName, "$ios_dir$", IOS_ASSEMBLIES_FOLDER);
ReplaceTextInFiles(specCopyName, "$windows_dir$", UWP_ASSEMBLIES_FOLDER);
ReplaceTextInFiles(specCopyName, "$android_dir$", ANDROID_ASSEMBLIES_FOLDER);
var spec = GetFiles(specCopyName);
Information("Building a NuGet package for " + module.DotNetModule + " version " + module.NuGetVersion);
NuGetPack(spec, new NuGetPackSettings {
BasePath = basePath,
Verbosity = NuGetVerbosity.Detailed,
Version = module.NuGetVersion
});
// Clean up
DeleteFiles(specCopyName);
}
MoveFiles("Microsoft.Azure.Mobile*.nupkg", "output");
}).OnError(HandleError);
// Add version to nuspecs for vsts (the release definition does not have the solutions and thus cannot extract a version from them)
Task("PrepareNuspecsForVSTS").IsDependentOn("Version").Does(()=>
{
foreach (var module in MOBILECENTER_MODULES)
{
ReplaceTextInFiles("./nuget/" + module.MainNuspecFilename, "$version$", module.NuGetVersion);
}
});
// Upload assemblies to Azure storage
Task("UploadAssemblies")
.IsDependentOn("PrepareAssemblies")
.Does(()=>
{
// The environment variables below must be set for this task to succeed
var apiKey = EnvironmentVariable("AZURE_STORAGE_ACCESS_KEY");
var accountName = EnvironmentVariable("AZURE_STORAGE_ACCOUNT");
foreach (var assemblyGroup in PLATFORM_PATHS.UploadAssemblyGroups)
{
var destinationFolder = DOWNLOADED_ASSEMBLIES_FOLDER + "/" + assemblyGroup.AssemblyFolder;
CleanDirectory(destinationFolder);
CopyFiles(assemblyGroup.AssemblyPaths, destinationFolder);
}
Information("Uploading to blob " + PLATFORM_PATHS.UploadAssembliesZip);
Zip(DOWNLOADED_ASSEMBLIES_FOLDER, PLATFORM_PATHS.UploadAssembliesZip);
AzureStorage.UploadFileToBlob(new AzureStorageSettings
{
AccountName = accountName,
ContainerName = "sdk",
BlobName = PLATFORM_PATHS.UploadAssembliesZip,
Key = apiKey,
UseHttps = true
}, PLATFORM_PATHS.UploadAssembliesZip);
}).OnError(HandleError).Finally(()=>RunTarget("RemoveTemporaries"));
// Download assemblies from azure storage
Task("DownloadAssemblies").Does(()=>
{
Information("Fetching assemblies from url: " + PLATFORM_PATHS.DownloadUrl);
CleanDirectory(DOWNLOADED_ASSEMBLIES_FOLDER);
DownloadFile(PLATFORM_PATHS.DownloadUrl, PLATFORM_PATHS.DownloadAssembliesZip);
Unzip(PLATFORM_PATHS.DownloadAssembliesZip, DOWNLOADED_ASSEMBLIES_FOLDER);
DeleteFiles(PLATFORM_PATHS.DownloadAssembliesZip);
Information("Successfully downloaded assemblies.");
}).OnError(HandleError);
Task("MergeAssemblies")
.IsDependentOn("PrepareAssemblies")
.IsDependentOn("DownloadAssemblies")
.IsDependentOn("Version")
.Does(()=>
{
Information("Beginning complete package creation...");
// Copy the downloaded files to their proper locations so the structure is as if
// the downloaded assemblies were built locally (for the nuspecs to work)
foreach (var assemblyFolder in PLATFORM_PATHS.DownloadAssemblyFolders)
{
CleanDirectory(assemblyFolder);
var files = GetFiles(DOWNLOADED_ASSEMBLIES_FOLDER + "/" + assemblyFolder + "/*");
CopyFiles(files, assemblyFolder);
}
// Create NuGet packages
foreach (var module in MOBILECENTER_MODULES)
{
// Prepare nuspec by making substitutions in a copied nuspec (to avoid altering the original)
var specCopyName = TEMPORARY_PREFIX + "spec_copy.nuspec";
CopyFile("nuget/" + module.MainNuspecFilename, specCopyName);
ReplaceTextInFiles(specCopyName, "$pcl_dir$", PCL_ASSEMBLIES_FOLDER);
ReplaceTextInFiles(specCopyName, "$ios_dir$", IOS_ASSEMBLIES_FOLDER);
ReplaceTextInFiles(specCopyName, "$windows_dir$", UWP_ASSEMBLIES_FOLDER);
ReplaceTextInFiles(specCopyName, "$android_dir$", ANDROID_ASSEMBLIES_FOLDER);
var spec = GetFiles(specCopyName);
// Create the NuGet package
Information("Building a NuGet package for " + module.DotNetModule + " version " + module.NuGetVersion);
NuGetPack(spec, new NuGetPackSettings {
Verbosity = NuGetVerbosity.Detailed,
Version = module.NuGetVersion
});
// Clean up
DeleteFiles(specCopyName);
}
CleanDirectory("output");
MoveFiles("*.nupkg", "output");
}).OnError(HandleError).Finally(()=>RunTarget("RemoveTemporaries"));
Task("TestApps").IsDependentOn("UITest").Does(() =>
{
// Build tests and package the applications
// It is important that the entire solution is built before rebuilding the iOS and Android versions
// due to an apparent bug that causes improper linking of the forms application to iOS
MSBuild("./MobileCenter-SDK-Test.sln", c => c.Configuration = "Release");
MDToolBuild("./Tests/iOS/Contoso.Forms.Test.iOS.csproj", c => c.Configuration = "Release|iPhone");
AndroidPackage("./Tests/Droid/Contoso.Forms.Test.Droid.csproj", false, c => c.Configuration = "Release");
MSBuild("./Tests/UITests/Contoso.Forms.Test.UITests.csproj", c => c.Configuration = "Release");
}).OnError(HandleError);
Task("RestoreTestPackages").Does(() =>
{
NuGetRestore("./MobileCenter-SDK-Test.sln");
NuGetUpdate("./Tests/Contoso.Forms.Test/packages.config");
NuGetUpdate("./Tests/iOS/packages.config");
NuGetUpdate("./Tests/Droid/packages.config");
}).OnError(HandleError);
// Remove any uploaded nugets from azure storage
Task("CleanAzureStorage").Does(()=>
{
var apiKey = EnvironmentVariable("AZURE_STORAGE_ACCESS_KEY");
var accountName = EnvironmentVariable("AZURE_STORAGE_ACCOUNT");
try
{
AzureStorage.DeleteBlob(new AzureStorageSettings
{
AccountName = accountName,
ContainerName = "sdk",
BlobName = MAC_ASSEMBLIES_ZIP + STORAGE_ID,
Key = apiKey,
UseHttps = true
});
AzureStorage.DeleteBlob(new AzureStorageSettings
{
AccountName = accountName,
ContainerName = "sdk",
BlobName = WINDOWS_ASSEMBLIES_ZIP + STORAGE_ID,
Key = apiKey,
UseHttps = true
});
}
catch
{
// not an error if the blob is not found
}
}).OnError(HandleError);
// Remove all temporary files and folders
Task("RemoveTemporaries").Does(()=>
{
DeleteFiles(TEMPORARY_PREFIX + "*");
var dirs = GetDirectories(TEMPORARY_PREFIX + "*");
foreach (var directory in dirs)
{
DeleteDirectory(directory, true);
}
DeleteFiles("./nuget/*.temp.nuspec");
});
// Clean up files/directories.
Task("clean")
.IsDependentOn("RemoveTemporaries")
.Does(() =>
{
DeleteDirectoryIfExists("externals");
DeleteDirectoryIfExists("output");
DeleteFiles("./*.nupkg");
CleanDirectories("./**/bin");
CleanDirectories("./**/obj");
});
Task("PrepareAssemblyPathsVSTS").Does(()=>
{
var iosAssemblies = EnvironmentVariable("IOS_ASSEMBLY_PATH_NUSPEC");
var androidAssemblies = EnvironmentVariable("ANDROID_ASSEMBLY_PATH_NUSPEC");
var pclAssemblies = EnvironmentVariable("PCL_ASSEMBLY_PATH_NUSPEC");
var uwpAssemblies = EnvironmentVariable("UWP_ASSEMBLY_PATH_NUSPEC");
var nuspecPathPrefix = EnvironmentVariable("NUSPEC_PATH");
foreach (var module in MOBILECENTER_MODULES)
{
ReplaceTextInFiles(nuspecPathPrefix + module.MainNuspecFilename, "$pcl_dir$", pclAssemblies);
ReplaceTextInFiles(nuspecPathPrefix + module.MainNuspecFilename, "$ios_dir$", iosAssemblies);
ReplaceTextInFiles(nuspecPathPrefix + module.MainNuspecFilename, "$windows_dir$", uwpAssemblies);
ReplaceTextInFiles(nuspecPathPrefix + module.MainNuspecFilename, "$android_dir$", androidAssemblies);
}
}).OnError(HandleError);
Task("NugetPackVSTS").Does(()=>
{
var nuspecPathPrefix = EnvironmentVariable("NUSPEC_PATH");
foreach (var module in MOBILECENTER_MODULES)
{
var spec = GetFiles(nuspecPathPrefix + module.MainNuspecFilename);
// Create the NuGet packages
Information("Building a NuGet package for " + module.MainNuspecFilename);
NuGetPack(spec, new NuGetPackSettings {
Verbosity = NuGetVerbosity.Detailed,
});
}
}).OnError(HandleError);
// Copy files to a clean directory using string names instead of FilePath[] and DirectoryPath
void CopyFiles(IEnumerable<string> files, string targetDirectory, bool clean = true)
{
if (clean)
{
CleanDirectory(targetDirectory);
}
foreach (var file in files)
{
CopyFile(file, targetDirectory + "/" + System.IO.Path.GetFileName(file));
}
}
void DeleteDirectoryIfExists(string directoryName)
{
if (DirectoryExists(directoryName))
{
DeleteDirectory(directoryName, true);
}
}
void CleanDirectory(string directoryName)
{
DeleteDirectoryIfExists(directoryName);
CreateDirectory(directoryName);
}
void HandleError(Exception exception)
{
RunTarget("clean");
throw exception;
}
RunTarget(TARGET);