-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.cake
169 lines (138 loc) · 4.88 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
//Addins
#addin Cake.VersionReader
#addin Cake.FileHelpers
#addin Cake.Git
//Variables
var target = Argument ("target", "Default");
var buildType = Argument("Configuration", "Release");
var buildTags = new string[] { "Debug", "403", "45" };
var buildDirectories = new string[] { "./bin/Debug", "./bin/net403", "./bin/net45" };
var configurationList = new string[] { "Debug", "net40", "net45" };
var wpfBinDirectory = "./WpfView/bin";
var wpfPath = "./WpfView/wpfview.csproj";
var wpfSpec = "./WpfView/WpfView.nuspec";
var wpfBinary = "./WpfView/bin/net403/LiveCharts.Wpf.dll";
var formsBinDirectory = "./WinFormsView/bin";
var formsPath = "./WinFormsView/WinFormsView.csproj";
var formsSpec = "./WinFormsView/WinFormsView.nuspec";
var formsBinary = "./WinFormsView/bin/net403/LiveCharts.WinForms.dll";
//Main Tasks
//Print out configuration
Task("OutputArguments")
.Does(() =>
{
Information("Target: " + target);
Information("Build Type: " + buildType);
});
//Build Core
Task("Core")
.Does(() =>
{
Information("-- Core - " + buildType.ToUpper() + " --");
var ouputDirectory = "./bin/" + buildType;
if(!DirectoryExists(ouputDirectory)) CreateDirectory(ouputDirectory);
BuildProject("./Core/Core.csproj", ouputDirectory, buildType, "AnyCPU");
BuildProject("./Core40/Core40.csproj", ouputDirectory, buildType, "AnyCPU");
if(buildType == "Release") NugetPack("./Core/Core.nuspec", "./Core/bin/Release/LiveCharts.dll");
Information("-- Core Packed --");
});
//Build WPF
Task("WPF")
.Does(() =>
{
if(!DirectoryExists(wpfBinDirectory))
{
CreateDirectory(wpfBinDirectory);
}
for(var r = 0; r < buildTags.Length; r++)
{
Information("-- WPF " + buildTags[r].ToUpper() + " --");
if(!DirectoryExists(buildDirectories[r]))
{
CreateDirectory(buildDirectories[r]);
}
BuildProject(wpfPath, buildDirectories[r], configurationList[r], "AnyCPU");
}
if(buildType == "Release")
{
NugetPack(wpfSpec, wpfBinary);
}
Information("-- WPF Packed --");
});
Task("UWP")
.Does(() =>
{
Information("-- UWP - " + buildType.ToUpper() + " --");
if(!DirectoryExists("./bin/AnyCPU")) CreateDirectory("./bin/AnyCPU");
BuildProject("./UwpView/UwpView.csproj", "./bin/AnyCPU", buildType, "AnyCPU");
if(buildType == "Release") NugetPack("./UwpView/UwpView.nuspec", "./UwpView/bin/AnyCPU/LiveCharts.Uwp.dll");
Information("-- UWP Packed --");
});
Task("WinForms")
.Does(() =>
{
if(!DirectoryExists(formsBinDirectory))
{
CreateDirectory(formsBinDirectory);
}
for(var r = 0; r < buildTags.Length; r++)
{
Information("-- WinForms " + buildTags[r].ToUpper() + " --");
if(!DirectoryExists(buildDirectories[r]))
{
CreateDirectory(buildDirectories[r]);
}
BuildProject(formsPath, buildDirectories[r], configurationList[r], "AnyCPU");
}
if(buildType == "Release")
{
NugetPack(formsSpec, formsBinary);
}
Information("-- WinForms Packed --");
});
Task("Default")
.IsDependentOn("OutputArguments")
.IsDependentOn("Core")
.IsDependentOn("WPF")
.IsDependentOn("UWP")
.IsDependentOn("WinForms");
//Entry point for Cake build
RunTarget (target);
//Helper Methods
//Build a project
public void BuildProject(string path, string outputPath, string configuration, string platform)
{
Information("Building " + path);
try
{
DotNetBuild(path, settings =>
settings.SetConfiguration(configuration)
.WithProperty("Platform", platform)
.WithTarget("Clean,Build")
.WithProperty("OutputPath", outputPath)
.SetVerbosity(Cake.Core.Diagnostics.Verbosity.Minimal
));
}
catch(Exception ex)
{
Error("An error occured while trying to build {0} with {1}", path, configuration);
}
Information("Build completed");
}
//Pack into Nuget package
public void NugetPack(string nuspecPath, string mainBinaryPath)
{
Information("Packing " + nuspecPath);
var binary = MakeAbsolute(File(mainBinaryPath));
var binaryVersion = GetFullVersionNumber(binary);
ReplaceRegexInFiles(nuspecPath, "0.0.0.0", binaryVersion);
NuGetPack(nuspecPath, new NuGetPackSettings{
Verbosity = NuGetVerbosity.Quiet,
OutputDirectory = "./"
});
//We revert the nuspec file to the check out one, otherwise we cannot build it again with a new version
//This should rather use XmlPoke but cannot yet get it to work
var fullNuspecPath = MakeAbsolute(File(nuspecPath));
GitCheckout("./", fullNuspecPath);
Information("Packing completed");
}