1
+ #addin "Cake.Xamarin"
2
+ #addin nuget : ? package= Cake . Git
3
+
4
+ using Path = System . IO . Path ;
5
+ using System . Xml . Linq ;
6
+ using System . Xml ;
7
+
8
+ var target = Argument ( "target" , "Build" ) ;
9
+
10
+ var NuGetTargetDir = MakeAbsolute ( Directory ( ".build/out/nuget" ) ) ;
11
+ var BuildTargetDir = MakeAbsolute ( Directory ( ".build/out/lib" ) ) ;
12
+ var ProjectSources = MakeAbsolute ( Directory ( "./Source" ) ) ;
13
+ var NuspecFiles = new [ ] { ".build/Plugin.Badge.nuspec" } ;
14
+
15
+ string GetProjectDir ( string projectName )
16
+ {
17
+ return ProjectSources . Combine ( projectName ) . CombineWithFilePath ( projectName + ".csproj" ) . FullPath ;
18
+ }
19
+
20
+ void BuildProject ( string projectName , string targetSubDir )
21
+ {
22
+ Information ( "Building {0} ..." , projectName ) ;
23
+ var project = GetProjectDir ( projectName ) ;
24
+ var outputDir = BuildTargetDir . Combine ( targetSubDir ) ;
25
+ MSBuild ( project , settings => settings
26
+ . SetConfiguration ( "Release" )
27
+ . WithTarget ( "Build" )
28
+ . SetMSBuildPlatform ( MSBuildPlatform . x86 )
29
+ . WithProperty ( "OutDir" , outputDir . FullPath ) ) ;
30
+ }
31
+
32
+ // string NuVersionGet (string specFile)
33
+ // {
34
+ // var doc = System.Xml.Linq.XDocument.Load(specFile);
35
+ // var versionElements = doc.Descendants(XName.Get("version", doc.Root.Name.NamespaceName));
36
+ // return versionElements.First().Value;
37
+ // }
38
+
39
+ // void NuVersionSet (string specFile, string version)
40
+ // {
41
+ // var xmlDocument = System.Xml.Linq.XDocument.Load(specFile);
42
+ // var nsmgr = new XmlNamespaceManager(new XmlNameTable());
43
+ // nsmgr.AddNamespace("ns", "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd");
44
+ // var node = xmlDocument.Document.SelectSingleNode("//ns:version", nsmgr);
45
+ // node.InnerText = version;
46
+ // xmlDocument.Save(specFile);
47
+ // }
48
+
49
+ Task ( "Restore" )
50
+ . Does ( ( ) =>
51
+ {
52
+ var solutions = GetFiles ( "./Source/*.sln" ) ;
53
+ // Restore all NuGet packages.
54
+ foreach ( var solution in solutions )
55
+ {
56
+ Information ( "Restoring {0}" , solution ) ;
57
+ NuGetRestore ( solution ) ;
58
+ }
59
+ } ) ;
60
+
61
+ Task ( "Build" )
62
+ . IsDependentOn ( "Clean" )
63
+ . IsDependentOn ( "Restore" )
64
+ . Does ( ( ) =>
65
+ {
66
+ BuildProject ( "Plugin.Badge.Abstractions" , "netstandard1.4" ) ;
67
+ BuildProject ( "Plugin.Badge.Droid" , "android" ) ;
68
+ BuildProject ( "Plugin.Badge.iOS" , "ios" ) ;
69
+ BuildProject ( "Plugin.Badge.Mac" , "mac" ) ;
70
+ BuildProject ( "Plugin.Badge.UWP" , "uwp" ) ;
71
+ } ) ;
72
+
73
+ Task ( "Clean" ) . Does ( ( ) =>
74
+ {
75
+ if ( DirectoryExists ( BuildTargetDir ) )
76
+ DeleteDirectory ( BuildTargetDir , true ) ;
77
+
78
+ CleanDirectories ( "./**/bin" ) ;
79
+ CleanDirectories ( "./**/obj" ) ;
80
+ } ) ;
81
+
82
+ Task ( "Version" )
83
+ . Does ( ( ) => {
84
+ var version = Argument < string > ( "ver" , "" ) ;
85
+ var cleanVersion = System . Text . RegularExpressions . Regex . Replace ( version , @"[^\d\.].*$" , "" ) ;
86
+
87
+ if ( string . IsNullOrEmpty ( cleanVersion ) )
88
+ {
89
+ throw new ArgumentNullException ( nameof ( version ) ) ;
90
+ }
91
+
92
+ // ReplaceRegexInFiles("./your/AssemblyInfo.cs", "(?<=AssemblyVersion\\(\")(.+?)(?=\"\\))", cleanVersion);
93
+ } ) ;
94
+
95
+ Task ( "Pack" )
96
+ . IsDependentOn ( "Build" )
97
+ . Does ( ( ) =>
98
+ {
99
+ foreach ( var nuspec in NuspecFiles )
100
+ {
101
+ NuGetPack ( nuspec , new NuGetPackSettings ( )
102
+ {
103
+ OutputDirectory = "./.build/nuget"
104
+ } ) ;
105
+ }
106
+ } ) ;
107
+
108
+ Task ( "Publish" )
109
+ . IsDependentOn ( "Build" )
110
+ . Does ( ( ) =>
111
+ {
112
+ var nupack = GetFiles ( "./.build/nuget/*.nuspec" ) . FirstOrDefault ( ) ;
113
+ NuGetPush ( nupack . FullPath ) ;
114
+ } ) ;
115
+
116
+ RunTarget ( target ) ;
0 commit comments