forked from xabre/xamarin-forms-tab-badge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
104 lines (89 loc) · 3.12 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
#addin nuget:?package=Cake.Git&version=0.21
#addin nuget:?package=Cake.FileHelpers&version=3.2.0
using Path = System.IO.Path;
using System.Xml.Linq;
using System.Xml;
var target = Argument("target", "Build");
var NuGetTargetDir = MakeAbsolute(Directory(".build/out/nuget"));
var BuildTargetDir = MakeAbsolute(Directory(".build/out/lib"));
var ProjectSources = MakeAbsolute(Directory("./Source"));
var NuspecFiles = new [] { ".build/Plugin.Badge.nuspec" };
string GetProjectDir(string projectName)
{
return ProjectSources.Combine(projectName).CombineWithFilePath(projectName + ".csproj").FullPath;
}
void BuildProject(string projectName, string targetSubDir)
{
Information("Building {0} ...", projectName);
var project = GetProjectDir(projectName);
var outputDir = BuildTargetDir.Combine(targetSubDir);
MSBuild(project, settings => settings
.SetConfiguration("Release")
.WithTarget("Build")
.UseToolVersion(MSBuildToolVersion.VS2019)
.SetMSBuildPlatform(MSBuildPlatform.x86)
.WithProperty("OutDir", outputDir.FullPath));
}
Task("Restore")
.Does(() =>
{
var solutions = GetFiles("./Source/*.sln");
// Restore all NuGet packages.
foreach(var solution in solutions)
{
Information("Restoring {0}", solution);
NuGetRestore(solution);
}
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
BuildProject("Plugin.Badge.Abstractions", "netstandard1.4");
BuildProject("Plugin.Badge.Droid", "android");
BuildProject("Plugin.Badge.iOS", "ios");
BuildProject("Plugin.Badge.Mac", "mac");
BuildProject("Plugin.Badge.UWP", "uwp");
BuildProject("Plugin.Badge.WPF", "wpf");
});
Task("Clean").Does (() =>
{
if (DirectoryExists (BuildTargetDir))
DeleteDirectory (BuildTargetDir, true);
CleanDirectories ("./**/bin");
CleanDirectories ("./**/obj");
});
// ./build.ps1 -Target UpdateVersion -newVersion="2.0.1"
Task("UpdateVersion")
.Does(() => {
var version = Argument<string>("newVersion", "");
var cleanVersion = System.Text.RegularExpressions.Regex.Replace(version, @"[^\d\.].*$", "");
if(string.IsNullOrEmpty(cleanVersion))
{
throw new ArgumentNullException(nameof(version));
}
ReplaceRegexInFiles("./**/AssemblyInfo.cs", "(?<=AssemblyVersion\\(\")(.+?)(?=\"\\))", cleanVersion);
ReplaceRegexInFiles("./**/*.nuspec", "(?<=<version>)(.+?)(?=</version>)", cleanVersion);
});
Task("Pack")
.IsDependentOn("Build")
.Does(() =>
{
foreach(var nuspec in NuspecFiles)
{
NuGetPack(nuspec, new NuGetPackSettings()
{
OutputDirectory = "./.build/nuget"
});
}
});
Task("Publish")
.IsDependentOn("Pack")
.Does(() =>
{
var nupack = GetFiles(".build/nuget/*.nupkg").LastOrDefault();
Information($"Pushing package: {nupack.FullPath}") ;
NuGetPush(nupack.FullPath, new NuGetPushSettings(){ Source = "https://nuget.org" });
});
RunTarget(target);