forked from dotnet/maui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
1482 lines (1232 loc) · 49.4 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
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
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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
/*
Windows CMD:
build.cmd -Target NugetPack
build.cmd -Target NugetPack -ScriptArgs '--packageVersion="9.9.9-custom"','--configuration="Release"'
PowerShell:
./build.ps1 -Target NugetPack
./build.ps1 -Target NugetPack -ScriptArgs '--packageVersion="9.9.9-custom"'
*/
//////////////////////////////////////////////////////////////////////
// ADDINS
//////////////////////////////////////////////////////////////////////
#addin "nuget:?package=Cake.Android.SdkManager&version=3.0.2"
#addin "nuget:?package=Cake.Boots&version=1.0.4.600-preview1"
#addin "nuget:?package=Cake.AppleSimulator&version=0.2.0"
#addin "nuget:?package=Cake.FileHelpers&version=3.2.1"
//////////////////////////////////////////////////////////////////////
// TOOLS
//////////////////////////////////////////////////////////////////////
#tool nuget:?package=NUnit.ConsoleRunner&version=3.11.1
#tool "nuget:?package=nuget.commandline&version=5.8.1"
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
string agentName = EnvironmentVariable("AGENT_NAME", "");
bool isCIBuild = !String.IsNullOrWhiteSpace(agentName);
string artifactStagingDirectory = EnvironmentVariable("BUILD_ARTIFACTSTAGINGDIRECTORY", ".");
string workingDirectory = EnvironmentVariable("SYSTEM_DEFAULTWORKINGDIRECTORY", ".");
var configuration = Argument("BUILD_CONFIGURATION", "Debug");
var target = Argument("target", "Default");
if(String.IsNullOrWhiteSpace(target))
target = "Default";
var IOS_SIM_NAME = GetBuildVariable("IOS_SIM_NAME", "iPhone 8");
var IOS_SIM_RUNTIME = GetBuildVariable("IOS_SIM_RUNTIME", "com.apple.CoreSimulator.SimRuntime.iOS-14-4");
var IOS_CONTROLGALLERY = "src/Compatibility/ControlGallery/src/iOS/";
var IOS_CONTROLGALLERY_PROJ = $"{IOS_CONTROLGALLERY}Compatibility.ControlGallery.iOS.csproj";
var IOS_TEST_PROJ = "./src/Compatibility/ControlGallery/test/iOS.UITests/Compatibility.ControlGallery.iOS.UITests.csproj";
var IOS_TEST_LIBRARY = Argument("IOS_TEST_LIBRARY", $"./src/Compatibility/ControlGallery/test/iOS.UITests/bin/{configuration}/Microsoft.Maui.Controls.iOS.UITests.dll");
var IOS_IPA_PATH = Argument("IOS_IPA_PATH", $"./src/Compatibility/ControlGallery/src/iOS/bin/iPhoneSimulator/{configuration}/CompatibilityControlGalleryiOS.app");
var IOS_BUNDLE_ID = "com.microsoft.mauicompatibilitygallery";
var IOS_BUILD_IPA = Argument("IOS_BUILD_IPA", (target == "cg-ios-deploy") ? true : (false || isCIBuild) );
Guid IOS_SIM_UDID = Argument("IOS_SIM_UDID", Guid.Empty);
var UWP_PACKAGE_ID = "0d4424f6-1e29-4476-ac00-ba22c3789cb6";
var UWP_TEST_LIBRARY = GetBuildVariable("UWP_TEST_LIBRARY", $"./src/Compatibility/ControlGallery/test/Xamarin.Forms.Core.Windows.UITests/bin/{configuration}/Xamarin.Forms.Core.Windows.UITests.dll");
var UWP_PFX_PATH = Argument("UWP_PFX_PATH", "Xamarin.Forms.ControlGallery.WindowsUniversal\\Xamarin.Forms.ControlGallery.WindowsUniversal_TemporaryKey.pfx");
var UWP_APP_PACKAGES_PATH = Argument("UWP_APP_PACKAGES_PATH", "*/AppPackages/");
var UWP_APP_DRIVER_INSTALL_PATH = Argument("UWP_APP_DRIVER_INSTALL_PATH", "https://github.com/microsoft/WinAppDriver/releases/download/v1.2-RC/WindowsApplicationDriver.msi");
var ANDROID_BUNDLE_ID = "com.microsoft.mauicompatibilitygallery";
var ANDROID_CONTROLGALLERY = "src/Compatibility/ControlGallery/src/Android/";
var ANDROID_CONTROLGALLERY_PROJ = $"{ANDROID_CONTROLGALLERY}Compatibility.ControlGallery.Android.csproj";
var ANDROID_RENDERERS = Argument("ANDROID_RENDERERS", "FAST");
var ANDROID_TEST_PROJ = "./src/Compatibility/ControlGallery/test/Android.UITests/Compatibility.ControlGallery.Android.UITests.csproj";
var BUILD_TASKS_PROJ ="Microsoft.Maui.BuildTasks.sln";
var XamarinFormsVersion = Argument("XamarinFormsVersion", "");
var packageVersion = GetBuildVariable("packageVersion", "0.1.0-p2");
var releaseChannelArg = Argument("CHANNEL", "Stable");
releaseChannelArg = EnvironmentVariable("CHANNEL") ?? releaseChannelArg;
var teamProject = Argument("TeamProject", "");
bool isHostedAgent = agentName.StartsWith("Azure Pipelines") || agentName.StartsWith("Hosted Agent");
var MAUI_SLN = "./Microsoft.Maui.sln";
var CONTROLGALLERY_SLN = "./ControlGallery.sln";
string defaultUnitTestWhere = "";
if(target.ToLower().Contains("uwp"))
defaultUnitTestWhere = "cat != UwpIgnore";
var NUNIT_TEST_WHERE = Argument("NUNIT_TEST_WHERE", defaultUnitTestWhere);
NUNIT_TEST_WHERE = ParseDevOpsInputs(NUNIT_TEST_WHERE);
var ANDROID_HOME = EnvironmentVariable("ANDROID_HOME") ??
(IsRunningOnWindows () ? "C:\\Program Files (x86)\\Android\\android-sdk\\" : "");
string MSBuildArgumentsENV = EnvironmentVariable("MSBuildArguments", "");
string MSBuildArgumentsARGS = Argument("MSBuildArguments", "");
string MSBuildArguments;
MSBuildArguments = $"{MSBuildArgumentsENV} {MSBuildArgumentsARGS}";
Information("MSBuildArguments: {0}", MSBuildArguments);
string androidEmulators = EnvironmentVariable("ANDROID_EMULATORS", "");
string androidSdks = EnvironmentVariable("ANDROID_API_SDKS",
// build/platform tools
"build-tools;29.0.3," +
"build-tools;30.0.2," +
"platform-tools," +
// apis
"platforms;android-26," +
"platforms;android-27," +
"platforms;android-28," +
"platforms;android-29," +
"platforms;android-30," +
// emulators
androidEmulators);
Information("ANDROID_API_SDKS: {0}", androidSdks);
string[] androidSdkManagerInstalls = androidSdks.Split(',');
(string name, string location, string featureList)[] windowsSdksInstalls = new (string name, string location, string featureList)[]
{
("10.0.19041.0", "https://go.microsoft.com/fwlink/p/?linkid=2120843", "OptionId.WindowsPerformanceToolkit OptionId.WindowsDesktopDebuggers OptionId.AvrfExternal OptionId.WindowsSoftwareLogoToolkit OptionId.MSIInstallTools OptionId.SigningTools OptionId.UWPManaged OptionId.UWPCPP OptionId.UWPLocalized OptionId.DesktopCPPx86 OptionId.DesktopCPPx64 OptionId.DesktopCPParm OptionId.DesktopCPParm64"),
("10.0.18362.0", "https://go.microsoft.com/fwlink/?linkid=2083338", "+"),
("10.0.16299.0", "https://go.microsoft.com/fwlink/p/?linkid=864422", "+"),
("10.0.14393.0", "https://go.microsoft.com/fwlink/p/?LinkId=838916", "+")
};
string[] netFrameworkSdksLocalInstall = new string[]
{
"https://go.microsoft.com/fwlink/?linkid=2099470", //NET461 SDK
"https://go.microsoft.com/fwlink/?linkid=874338", //NET472 SDK
"https://go.microsoft.com/fwlink/?linkid=2099465", //NET47
"https://download.microsoft.com/download/A/1/D/A1D07600-6915-4CB8-A931-9A980EF47BB7/NDP47-DevPack-KB3186612-ENU.exe", //net47 targeting pack
"https://go.microsoft.com/fwlink/?linkid=2088517", //NET48 SDK
};
// these don't run on CI
(string msiUrl, string cabUrl)[] netframeworkMSI = new (string msiUrl, string cabUrl)[]
{
(
"https://download.visualstudio.microsoft.com/download/pr/34dae2b3-314f-465e-aba0-0a862c29638e/b2bc986f304acdd76fcd8f910012b656/sdk_tools462.msi",
"https://download.visualstudio.microsoft.com/download/pr/6283f4a0-36b3-4336-a6f2-c5afd9f8fdbb/ffbe35e429f7d5c1d3777d03b2f38a24/sdk_tools462.cab"
),
(
"https://download.visualstudio.microsoft.com/download/pr/0d63c72c-9341-4de6-b493-dc7ad0d01246/f16b6402b8f8fb3b95dde5c1c2e5a2b4/sdk_tools461.msi",
"https://download.visualstudio.microsoft.com/download/pr/3dc58ffd-d515-43a4-87bd-2aba395eab17/5bff8f781c9843d64bd2367898395c5e/sdk_tools461.cab"
),
(
"https://download.visualstudio.microsoft.com/download/pr/9d14aa59-3f7f-4fe6-85e9-3bc31031e1f2/88b90ec9d096ec382a001e1fbd4a6be8/sdk_tools472.msi",
"https://download.visualstudio.microsoft.com/download/pr/77f1d250-f253-4c48-849c-0f08c9c11e77/ab2aa8f856e686cd4ad1c921742f2eeb/sdk_tools472.cab"
)
};
Information ("XamarinFormsVersion: {0}", XamarinFormsVersion);
Information ("ANDROID_RENDERERS: {0}", ANDROID_RENDERERS);
Information ("configuration: {0}", configuration);
Information ("ANDROID_HOME: {0}", ANDROID_HOME);
Information ("Team Project: {0}", teamProject);
Information ("Agent.Name: {0}", agentName);
Information ("isCIBuild: {0}", isCIBuild);
Information ("artifactStagingDirectory: {0}", artifactStagingDirectory);
Information("workingDirectory: {0}", workingDirectory);
Information("NUNIT_TEST_WHERE: {0}", NUNIT_TEST_WHERE);
Information("TARGET: {0}", target);
var releaseChannel = ReleaseChannel.Stable;
if(releaseChannelArg == "Preview")
{
releaseChannel = ReleaseChannel.Preview;
}
Information ("Release Channel: {0}", releaseChannel);
string androidSDK_macos = "";
string monoSDK_macos = "";
string iOSSDK_macos = "";
string macSDK_macos = "";
string monoPatchVersion = "";
string monoMajorVersion = "";
string monoVersion = "";
if(releaseChannel == ReleaseChannel.Stable)
{
if(IsXcodeVersionAtLeast("12.0"))
{
}
else
{
monoMajorVersion = "";
monoPatchVersion = "";
iOSSDK_macos = $"https://bosstoragemirror.blob.core.windows.net/wrench/jenkins/d16-7-xcode11.7/3016ffe2b0ee27bf4a2d61e6161430d6bbd62f78/7/package/notarized/xamarin.ios-13.20.3.5.pkg";
macSDK_macos = $"https://bosstoragemirror.blob.core.windows.net/wrench/jenkins/d16-7-xcode11.7/3016ffe2b0ee27bf4a2d61e6161430d6bbd62f78/7/package/notarized/xamarin.mac-6.20.3.5.pkg";
}
}
if(String.IsNullOrWhiteSpace(monoSDK_macos))
{
if(String.IsNullOrWhiteSpace(monoPatchVersion))
monoVersion = $"{monoMajorVersion}";
else
monoVersion = $"{monoMajorVersion}.{monoPatchVersion}";
if(!String.IsNullOrWhiteSpace(monoVersion))
{
monoSDK_macos = $"https://download.mono-project.com/archive/{monoMajorVersion}/macos-10-universal/MonoFramework-MDK-{monoVersion}.macos10.xamarin.universal.pkg";
}
}
string androidSDK_windows = "";
string iOSSDK_windows = "";
string monoSDK_windows = "";
string macSDK_windows = "";
androidSDK_macos = EnvironmentVariable("ANDROID_SDK_MAC", androidSDK_macos);
iOSSDK_macos = EnvironmentVariable("IOS_SDK_MAC", iOSSDK_macos);
monoSDK_macos = EnvironmentVariable("MONO_SDK_MAC", monoSDK_macos);
macSDK_macos = EnvironmentVariable("MAC_SDK_MAC", macSDK_macos);
androidSDK_windows = EnvironmentVariable("ANDROID_SDK_WINDOWS", "");
iOSSDK_windows = EnvironmentVariable("IOS_SDK_WINDOWS", "");
monoSDK_windows = EnvironmentVariable("MONO_SDK_WINDOWS", "");
macSDK_windows = EnvironmentVariable("MAC_SDK_WINDOWS", "");
string androidSDK = IsRunningOnWindows() ? androidSDK_windows : androidSDK_macos;
string monoSDK = IsRunningOnWindows() ? monoSDK_windows : monoSDK_macos;
string iosSDK = IsRunningOnWindows() ? iOSSDK_windows : iOSSDK_macos;
string macSDK = IsRunningOnWindows() ? macSDK_windows : macSDK_macos;
Information ("androidSDK: {0}", androidSDK);
Information ("monoSDK: {0}", monoSDK);
Information ("macSDK: {0}", macSDK);
Information ("iosSDK: {0}", iosSDK);
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Description("Deletes all the obj/bin directories")
.Does(() =>
{
List<string> foldersToClean = new List<string>();
foreach (var item in new [] {"obj", "bin"})
{
foreach(string f in System.IO.Directory.GetDirectories(".", item, SearchOption.AllDirectories))
{
if(f.StartsWith(@".\bin") || f.StartsWith(@".\tools"))
continue;
// this is here as a safety check
if(!f.StartsWith(@".\src"))
continue;
CleanDirectories(f);
}
}
});
Task("provision-macsdk")
.Description("Install Xamarin.Mac SDK")
.Does(async () =>
{
if(!IsRunningOnWindows())
{
if(!String.IsNullOrWhiteSpace(macSDK))
await Boots(macSDK);
else
await Boots (Product.XamarinMac, releaseChannel);
}
else if(!String.IsNullOrWhiteSpace(macSDK))
await Boots(macSDK);
});
Task("provision-iossdk")
.Description("Install Xamarin.iOS SDK")
.Does(async () =>
{
if (!IsRunningOnWindows()) {
if(!String.IsNullOrWhiteSpace(iosSDK))
await Boots(iosSDK);
else
await Boots (Product.XamariniOS, releaseChannel);
}
else if(!String.IsNullOrWhiteSpace(iosSDK))
await Boots(iosSDK);
});
Task("provision-androidsdk")
.Description("Install Xamarin.Android SDK")
.Does(async () =>
{
Information ("ANDROID_HOME: {0}", ANDROID_HOME);
if(androidSdkManagerInstalls.Length > 0)
{
Information("Updating Android SDKs");
var androidSdkSettings = new AndroidSdkManagerToolSettings {
SkipVersionCheck = true
};
if(!String.IsNullOrWhiteSpace(ANDROID_HOME))
androidSdkSettings.SdkRoot = ANDROID_HOME;
try{
AcceptLicenses (androidSdkSettings);
}
catch(Exception exc)
{
Information("AcceptLicenses: {0}", exc);
}
try{
AndroidSdkManagerUpdateAll (androidSdkSettings);
}
catch(Exception exc)
{
Information("AndroidSdkManagerUpdateAll: {0}", exc);
}
try{
AcceptLicenses (androidSdkSettings);
}
catch(Exception exc)
{
Information("AcceptLicenses: {0}", exc);
}
try{
AndroidSdkManagerInstall (androidSdkManagerInstalls, androidSdkSettings);
}
catch(Exception exc)
{
Information("AndroidSdkManagerInstall: {0}", exc);
}
}
if (!IsRunningOnWindows ()) {
if(!String.IsNullOrWhiteSpace(androidSDK))
{
await Boots (androidSDK);
}
else
await Boots (Product.XamarinAndroid, releaseChannel);
}
else if(!String.IsNullOrWhiteSpace(androidSDK))
{
await Boots (androidSDK);
}
});
Task("provision-monosdk")
.Description("Install Mono SDK")
.Does(async () =>
{
if(!IsRunningOnWindows())
{
if(!String.IsNullOrWhiteSpace(monoSDK))
await Boots(monoSDK);
else
await Boots (Product.Mono, releaseChannel);
}
else if(!String.IsNullOrWhiteSpace(monoSDK))
await Boots(monoSDK);
});
Task("provision-windowssdk")
.Description("Install Windows SDK")
.Does(() =>
{
if(IsRunningOnWindows() && !isHostedAgent)
{
int i = 0;
foreach(var windowsSdk in windowsSdksInstalls)
{
string sdkPath = System.IO.Path.Combine(@"C:\Program Files (x86)\Windows Kits\10\Platforms\UAP", windowsSdk.name);
if(DirectoryExists(sdkPath) && GetFiles(System.IO.Path.Combine(sdkPath, "*.*")).Count() > 0)
{
Information("Already Installed: {0}", sdkPath);
continue;
}
Information("Installing: {0}", sdkPath);
string installUrl = windowsSdk.location;
string installerPath = $"{System.IO.Path.GetTempPath()}" + $"WindowsSDK{i}.exe";
DownloadFile(installUrl, installerPath);
var result = StartProcess(installerPath, new ProcessSettings {
Arguments = new ProcessArgumentBuilder()
.Append(@"/features ")
.Append(windowsSdk.featureList)
.Append(@" /q")
}
);
i++;
}
}
});
Task("provision-netsdk-local")
.Description("Install .NET SDK")
.Does(() =>
{
if(IsRunningOnWindows() && (!isCIBuild || target == "provision-netsdk-local"))
{
foreach(var installUrl in netframeworkMSI)
{
string msiUrl = installUrl.msiUrl;
string cabUrl = installUrl.cabUrl;
string cabName = cabUrl.Split('/').Last();
string msiName = msiUrl.Split('/').Last();
string cabPath = $"{System.IO.Path.GetTempPath()}{cabName}";
Information("Downloading: {0} to {1}", cabUrl, cabPath);
DownloadFile(cabUrl, cabPath);
InstallMsiOrExe(msiUrl, null, msiName);
}
int i = 0;
foreach(var installUrl in netFrameworkSdksLocalInstall)
{
Information("Installing: {0}", installUrl);
string installerPath = $"{System.IO.Path.GetTempPath()}" + $"netSDKS{i}.exe";
DownloadFile(installUrl, installerPath);
var result = StartProcess(installerPath, new ProcessSettings {
Arguments = new ProcessArgumentBuilder()
.Append(@"/quiet")
}
);
i++;
}
}
});
Task ("cg-uwp")
.IsDependentOn("BuildTasks")
.Does (() =>
{
MSBuild ("Xamarin.Forms.ControlGallery.WindowsUniversal\\Xamarin.Forms.ControlGallery.WindowsUniversal.csproj",
GetMSBuildSettings().WithRestore());
});
Task ("cg-uwp-build-tests")
.IsDependentOn("BuildTasks")
.Does (() =>
{
MSBuild ("Xamarin.Forms.ControlGallery.WindowsUniversal\\Xamarin.Forms.ControlGallery.WindowsUniversal.csproj",
GetMSBuildSettings(null)
.WithProperty("AppxBundlePlatforms", "x86")
.WithProperty("AppxBundle", "Always")
.WithProperty("UapAppxPackageBuildMode", "StoreUpload")
.WithProperty("AppxPackageSigningEnabled", "true")
.WithProperty("PackageCertificateThumbprint", "a59087cc92a9a8117ffdb5255eaa155748f9f852")
.WithProperty("PackageCertificateKeyFile", "Xamarin.Forms.ControlGallery.WindowsUniversal_TemporaryKey.pfx")
.WithProperty("PackageCertificatePassword", "")
// The platform unit tests can't run when UseDotNetNativeToolchain is set to true so we force it off here
.WithProperty("UseDotNetNativeToolchain", "false")
.WithRestore()
);
MSBuild("Xamarin.Forms.Core.Windows.UITests\\Xamarin.Forms.Core.Windows.UITests.csproj",
GetMSBuildSettings(buildConfiguration:"Debug").WithRestore());
});
Task ("cg-uwp-deploy")
.WithCriteria(IsRunningOnWindows())
.Does (() =>
{
var uninstallPS = new Action (() => {
try {
StartProcess ("powershell",
"$app = Get-AppxPackage -Name " + UWP_PACKAGE_ID + "; if ($app) { Remove-AppxPackage -Package $app.PackageFullName }");
} catch { }
});
// Try to uninstall the app if it exists from before
uninstallPS();
StartProcess("certutil", "-f -p \"\" -importpfx \"" + UWP_PFX_PATH + "\"");
// Install the appx
var dependencies = GetFiles(UWP_APP_PACKAGES_PATH + "*/Dependencies/x86/*.appx");
foreach (var dep in dependencies) {
try
{
Information("Installing Dependency appx: {0}", dep);
StartProcess("powershell", "Add-AppxPackage -Path \"" + MakeAbsolute(dep).FullPath + "\"");
}
catch(Exception exc)
{
Information("Error: {0}", exc);
}
}
var appxBundlePath = GetFiles(UWP_APP_PACKAGES_PATH + "*/*.appxbundle").First ();
Information("Installing appx: {0}", appxBundlePath);
StartProcess ("powershell", "Add-AppxPackage -Path \"" + MakeAbsolute(appxBundlePath).FullPath + "\"");
});
Task("cg-uwp-run-tests")
.IsDependentOn("cg-uwp-build-tests")
.IsDependentOn("cg-uwp-deploy")
.IsDependentOn("provision-uitests-uwp")
.IsDependentOn("_cg-uwp-run-tests");
Task("_cg-uwp-run-tests")
.Does((ctx) =>
{
System.Diagnostics.Process process = null;
if(!isHostedAgent)
{
try
{
var info = new System.Diagnostics.ProcessStartInfo(@"C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe")
{
};
process = System.Diagnostics.Process.Start(info);
}
catch(Exception exc)
{
Information("Failed: {0}", exc);
}
}
var settings = new NUnit3Settings {
Params = new Dictionary<string, string>()
{
{"IncludeScreenShots", "true"}
}
};
try
{
RunTests(UWP_TEST_LIBRARY, settings, ctx);
}
finally
{
try
{
process?.Kill();
}
catch{}
}
});
Task("cg-uwp-run-tests-ci")
.IsDependentOn("provision-windowssdk")
.IsDependentOn("cg-uwp-deploy")
.IsDependentOn("_cg-uwp-run-tests")
.Does(() =>
{
});
Task("provision-uitests-uwp")
.WithCriteria(IsRunningOnWindows() && !isHostedAgent)
.Description("Installs and Starts WindowsApplicationDriver. Use WinAppDriverPath to specify WinAppDriver Location.")
.Does(() =>
{
string installPath = Argument("WinAppDriverPath", @"C:\Program Files (x86)\");
string driverPath = System.IO.Path.Combine(installPath, "Windows Application Driver");
if(!DirectoryExists(driverPath))
{
try{
InstallMsiOrExe(UWP_APP_DRIVER_INSTALL_PATH, installPath);
}
catch(Exception e)
{
Information("Failed to Install Win App Driver: {0}", e);
}
}
});
async Task InstallMsiWithBoots(string msiFile, string installTo = null, string fileName = "InstallFile.msi")
{
bool success = false;
try
{
await Boots(msiFile);
success = true;
}
catch (System.Exception e)
{
Information("Boots failed: {0}", e);
}
if(success)
return;
try
{
InstallMsiOrExe(msiFile, installTo, fileName, !isCIBuild);
success = true;
}
catch (System.Exception e)
{
Information("Our attempt failed: {0}", e);
}
}
void InstallMsiOrExe(string msiFile, string installTo = null, string fileName = "InstallFile.msi", bool interactive = false)
{
if(msiFile.EndsWith(".exe") && fileName == "InstallFile.msi")
fileName = "InstallFile.exe";
string installerPath = $"{System.IO.Path.GetTempPath()}{fileName}";
try
{
Information ("Installing: {0}", msiFile);
DownloadFile(msiFile, installerPath);
Information("File Downloaded To: {0}", installerPath);
int result = -1;
if(msiFile.EndsWith(".exe"))
{
result = StartProcess(installerPath, new ProcessSettings {
Arguments = new ProcessArgumentBuilder()
.Append(@" /q")
}
);
}
else{
var argumentBuilder =
new ProcessArgumentBuilder()
.Append("/a")
.Append(installerPath);
if(!interactive)
argumentBuilder = argumentBuilder.Append("/qn");
if(!String.IsNullOrWhiteSpace(installTo))
{
Information("Installing into: {0}", installTo);
argumentBuilder = argumentBuilder.Append("TARGETDIR=\"" + installTo + "\"");
}
result = StartProcess("msiexec", new ProcessSettings {
Arguments = argumentBuilder
});
}
if(result != 0)
throw new Exception("Failed to install: " + msiFile);
Information("File Installed: {0}", result);
}
catch(Exception exc)
{
Information("Failed to install {0} make sure you are running script as admin {1}", msiFile, exc);
throw;
}
finally{
DeleteFile(installerPath);
}
}
Task("provision")
.Description("Install SDKs required to build project")
.IsDependentOn("provision-macsdk")
.IsDependentOn("provision-iossdk")
.IsDependentOn("provision-androidsdk")
.IsDependentOn("provision-netsdk-local")
.IsDependentOn("provision-windowssdk")
.IsDependentOn("provision-monosdk"); // always provision monosdk last otherwise CI might fail
Task("NuGetPack")
.Description("Build and Create Nugets").Does(()=> {
var settings = new DotNetCoreToolSettings
{
DiagnosticOutput = true,
ArgumentCustomization = args => args.Append($"./eng/package.ps1 -configuration \"{configuration}\"")
};
DotNetCoreTool("pwsh", settings);
});;
Task("provision-powershell").Does(()=> {
var settings = new DotNetCoreToolSettings
{
DiagnosticOutput = true,
ArgumentCustomization = args=>args.Append("install --global PowerShell")
};
DotNetCoreTool("tool", settings);
});
Task("Restore")
.Description($"Restore target on {MAUI_SLN}")
.Does(() =>
{
try{
MSBuild(MAUI_SLN, GetMSBuildSettings().WithTarget("restore"));
}
catch{
// ignore restore errors that come from uwp
if(IsRunningOnWindows())
throw;
}
});
Task("WriteGoogleMapsAPIKey")
.Description("Write GoogleMapsAPIKey to Android Control Gallery")
.Does(() =>
{
string GoogleMapsAPIKey = Argument("GoogleMapsAPIKey", "");
if(!String.IsNullOrWhiteSpace(GoogleMapsAPIKey))
{
Information("Writing GoogleMapsAPIKey");
System.IO.File.WriteAllText($"{ANDROID_CONTROLGALLERY}/Properties/MapsKey.cs", "[assembly: Android.App.MetaData(\"com.google.android.maps.v2.API_KEY\", Value = \"" + GoogleMapsAPIKey + "\")]");
}
});
Task("BuildForNuget")
.IsDependentOn("BuildTasks")
.Description("Builds all necessary projects to create Nuget Packages")
.Does(() =>
{
try
{
var msbuildSettings = GetMSBuildSettings();
var binaryLogger = new MSBuildBinaryLogSettings {
Enabled = isCIBuild
};
msbuildSettings.BinaryLogger = binaryLogger;
binaryLogger.FileName = $"{artifactStagingDirectory}/Maui.Controls-{configuration}.binlog";
MSBuild(MAUI_SLN, msbuildSettings.WithRestore());
// // This currently fails on CI will revisit later
// if(isCIBuild)
// {
// MSBuild("./Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj", GetMSBuildSettings().WithTarget("Restore"));
// MSBuild("./Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj", GetMSBuildSettings());
// }
// MSBuild(MAUI_SLN, GetMSBuildSettings().WithTarget("Restore"));
// MSBuild("./Xamarin.Forms.DualScreen.sln", GetMSBuildSettings().WithTarget("Restore"));
// if(isCIBuild)
// {
// foreach(var platformProject in GetFiles("./Xamarin.*.UnitTests/*.csproj").Select(x=> x.FullPath))
// {
// if(platformProject.Contains("Xamarin.Forms.Xaml.UnitTests"))
// continue;
// Information("Building: {0}", platformProject);
// MSBuild(platformProject,
// GetMSBuildSettings().WithRestore());
// }
// }
// MSBuild(MAUI_SLN, GetMSBuildSettings().WithTarget("Restore"));
// MSBuild("./Xamarin.Forms.DualScreen.sln", GetMSBuildSettings().WithTarget("Restore"));
// msbuildSettings.BinaryLogger = binaryLogger;
// var platformProjects =
// GetFiles("./Xamarin.Forms.Platform.*/*.csproj")
// .Union(GetFiles("./Stubs/*/*.csproj"))
// .Union(GetFiles("./Xamarin.Forms.Maps.*/*.csproj"))
// .Union(GetFiles("./Xamarin.Forms.Pages.*/*.csproj"))
// .Union(GetFiles("./Xamarin.Forms.Material.*/*.csproj"))
// .Union(GetFiles("./Xamarin.Forms.Core.Design/*.csproj"))
// .Union(GetFiles("./Xamarin.Forms.Xaml.Design/*.csproj"))
// .Select(x=> x.FullPath).Distinct()
// .ToList();
// foreach(var platformProject in platformProjects)
// {
// if(platformProject.Contains("UnitTests"))
// continue;
// msbuildSettings = GetMSBuildSettings();
// string projectName = platformProject
// .Replace(' ', '_')
// .Split('/')
// .Last();
// binaryLogger.FileName = $"{artifactStagingDirectory}/{projectName}-{configuration}.binlog";
// msbuildSettings.BinaryLogger = binaryLogger;
// Information("Building: {0}", platformProject);
// MSBuild(platformProject,
// msbuildSettings);
// }
// dual screen
// XAML Tests are currently having issues compiling in Release Mode
// if(configuration == "Debug")
// {
// msbuildSettings = GetMSBuildSettings();
// msbuildSettings.BinaryLogger = binaryLogger;
// binaryLogger.FileName = $"{artifactStagingDirectory}/ControlGallery-{configuration}.binlog";
// MSBuild(CONTROLGALLERY_SLN, msbuildSettings.WithRestore());
// }
if(IsRunningOnWindows())
{
// msbuildSettings = GetMSBuildSettings();
// msbuildSettings.BinaryLogger = binaryLogger;
// binaryLogger.FileName = $"{artifactStagingDirectory}/dualscreen-{configuration}-csproj.binlog";
// MSBuild("./Xamarin.Forms.DualScreen/Xamarin.Forms.DualScreen.csproj",
// msbuildSettings
// .WithRestore()
// .WithTarget("rebuild"));
// msbuildSettings = GetMSBuildSettings();
// msbuildSettings.BinaryLogger = binaryLogger;
// binaryLogger.FileName = $"{artifactStagingDirectory}/win-maps-{configuration}-csproj.binlog";
// MSBuild("./Xamarin.Forms.Maps.UWP/Xamarin.Forms.Maps.UWP.csproj",
// msbuildSettings
// .WithProperty("UwpMinTargetFrameworks", "uap10.0.14393")
// .WithRestore());
// msbuildSettings = GetMSBuildSettings();
// msbuildSettings.BinaryLogger = binaryLogger;
// binaryLogger.FileName = $"{artifactStagingDirectory}/win-{configuration}-csproj.binlog";
// MSBuild("./src/Compatibility/Core/src/UAP/Compatibility.UAP.csproj",
// msbuildSettings
// .WithRestore()
// .WithTarget("rebuild")
// .WithProperty("DisableEmbeddedXbf", "false")
// .WithProperty("EnableTypeInfoReflection", "false"));
// msbuildSettings = GetMSBuildSettings();
// msbuildSettings.BinaryLogger = binaryLogger;
// binaryLogger.FileName = $"{artifactStagingDirectory}/ios-{configuration}-csproj.binlog";
// MSBuild("./Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj",
// msbuildSettings
// .WithTarget("rebuild"));
// msbuildSettings = GetMSBuildSettings();
// msbuildSettings.BinaryLogger = binaryLogger;
// binaryLogger.FileName = $"{artifactStagingDirectory}/macos-{configuration}-csproj.binlog";
// MSBuild("./Xamarin.Forms.Platform.MacOS/Xamarin.Forms.Platform.MacOS.csproj",
// msbuildSettings
// .WithTarget("rebuild"));
}
}
catch(Exception)
{
if(IsRunningOnWindows())
throw;
}
});
Task("BuildTasks")
.Description($"Build {BUILD_TASKS_PROJ}")
.Does(() =>
{
MSBuild(BUILD_TASKS_PROJ, GetMSBuildSettings().WithRestore());
});
Task("Build")
.Description("Builds all necessary projects to run Control Gallery")
.IsDependentOn("Restore")
.Does(() =>
{
try{
MSBuild(MAUI_SLN, GetMSBuildSettings().WithRestore());
}
catch(Exception)
{
if(IsRunningOnWindows())
throw;
}
});
Task("Android100")
.Description("Builds Monodroid10.0 targets")
.Does(() =>
{
MSBuild(MAUI_SLN,
GetMSBuildSettings()
.WithRestore()
.WithProperty("AndroidTargetFrameworks", "MonoAndroid10.0"));
});
Task("VS-NET6")
.Does(() =>
{
DotNetCoreBuild("./src/DotNet/Dotnet.csproj");
var ext = IsRunningOnWindows() ? ".exe" : "";
DotNetCoreBuild("./Microsoft.Maui.BuildTasks-net6.sln", new DotNetCoreBuildSettings { ToolPath = $"./bin/dotnet/dotnet{ext}" });
StartVisualStudioForDotNet6();
});
Task("VS-WINUI")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetCoreBuild("./src/DotNet/Dotnet.csproj");
var ext = IsRunningOnWindows() ? ".exe" : "";
StartProcess("powershell", $"./eng/dogfood.ps1 -JustCreateGlobalJSON");
DotNetCoreBuild("./Microsoft.Maui.BuildTasks-net6.sln", new DotNetCoreBuildSettings { ToolPath = $"./bin/dotnet/dotnet{ext}" });
MSBuild("Microsoft.Maui.WinUI.sln",
GetMSBuildSettings(includePrerelease:true).
WithRestore());
StartVisualStudioForDotNet6("./Microsoft.Maui.WinUI.sln");
});
Task("VS")
.Description("Builds projects necessary so solution compiles on VS")
.IsDependentOn("Clean")
.IsDependentOn("VSMAC")
.IsDependentOn("VSWINDOWS");
Task("VS-CG")
.Description("Builds projects necessary so solution compiles on VS")
.IsDependentOn("Clean")
.IsDependentOn("VSMAC")
.IsDependentOn("VSWINDOWS");
Task("VSWINDOWS")
.Description("Builds projects necessary so solution compiles on VS Windows")
.IsDependentOn("BuildTasks")
.WithCriteria(IsRunningOnWindows())
.Does(() =>
{
string sln = "Microsoft.Maui.sln";
if (target == "VS-CG")
sln = "Compatibility.ControlGallery.sln";
MSBuild(sln,
GetMSBuildSettings()
.WithRestore());
StartVisualStudio(sln);
});
Task("VSMAC")
.Description("Builds projects necessary so solution compiles on VSMAC")
.WithCriteria(!IsRunningOnWindows())
.IsDependentOn("BuildTasks")
.Does(() =>
{
string sln = "Microsoft.Maui.sln";
if (target == "VS-CG")
sln = "Compatibility.ControlGallery.sln";
MSBuild("src/Core/src/Core.csproj",
GetMSBuildSettings()
.WithRestore());
MSBuild("src/Controls/samples/Controls.Sample.Droid/Controls.Sample.Droid.csproj",
GetMSBuildSettings()
.WithRestore());
MSBuild("src/Controls/samples/Controls.Sample.iOS/Controls.Sample.iOS.csproj",
new MSBuildSettings().WithRestore());
MSBuild("src/Essentials/src/Essentials.csproj",
GetMSBuildSettings()
.WithRestore());
MSBuild("src/SingleProject/Resizetizer/src/Resizetizer.csproj", GetMSBuildSettings().WithRestore());
StartVisualStudio(sln);
});
Task("cg-android")
.Description("Builds Android Control Gallery")
.IsDependentOn("WriteGoogleMapsAPIKey")
.IsDependentOn("BuildTasks")
.Does(() =>
{
var buildSettings = GetMSBuildSettings();
buildSettings = buildSettings.WithRestore();