forked from XamlAnimatedGif/XamlAnimatedGif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
146 lines (127 loc) · 3.51 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
using System.Xml.Linq;
////////////////////
// Cake arguments //
////////////////////
var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Release");
//////////////////////////
// Variable definitions //
//////////////////////////
// Name of the project
var projectName = "XamlAnimatedGif";
// Solution to build
var solutionFile = $"./{projectName}.sln";
// Projects in the solution
var projects = new[]
{
$"{projectName}.Wpf",
$"{projectName}.Wpf.4.0",
$"{projectName}.WinRT"
};
var projectDirsToClean = new[] { "bin", "obj", "AppPackages" };
// Assemblies containing unit tests
var unitTestAssemblies = new string[] { };
// NuGet package ID; change if different from project name
var nugetId = projectName;
// Path to the nuspec file
var nuspecFile = $"./NuGet/{nugetId}.nuspec";
// Directory where the package will be generated
var nugetDir = $"./NuGet/{configuration}";
// Directory containing the package tree
var nupkgDir = $"{nugetDir}/nupkg";
// Files to include in NuGet package for each target
var nugetTargets = new[]
{
new { Name = "net45", Files = new[] { $"{projectName}.Wpf/bin/{configuration}/{projectName}.dll" } },
new { Name = "net40", Files = new[] { $"{projectName}.Wpf.4.0/bin/{configuration}/{projectName}.dll" } },
new { Name = "portable-win81+wpa81", Files = new[] { $"{projectName}.WinRT/bin/{configuration}/{projectName}.dll" } },
};
//////////////////////
// Setup / Teardown //
//////////////////////
Setup(() =>
{
// Executed BEFORE the first task.
Information("Running tasks...");
});
Teardown(() =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
//////////////////////
// Task definitions //
//////////////////////
// Clears the output directories
Task("Clean")
.Does(() =>
{
var dirsToClean =
from p in projects
from d in projectDirsToClean
select $"{p}/{d}";
CleanDirectories(dirsToClean);
CleanDirectory(nugetDir);
});
// Builds the solution
Task("Build")
.IsDependentOn("Clean")
.Does(() =>
{
foreach (var project in projects)
{
MSBuild(
$"{project}/{project}.csproj",
settings => settings.SetConfiguration(configuration));
}
});
// Runs the unit tests
Task("Test")
.WithCriteria(unitTestAssemblies.Any())
.IsDependentOn("Build")
.Does(() =>
{
NUnit(unitTestAssemblies);
});
// Creates the NuGet package
Task("Pack")
.IsDependentOn("Test")
.Does(() =>
{
CreateDirectory(nupkgDir);
foreach (var target in nugetTargets)
{
string targetDir = $"{nupkgDir}/lib/{target.Name}";
CreateDirectory(targetDir);
foreach (var file in target.Files)
{
CopyFileToDirectory(file, targetDir);
}
}
var packSettings = new NuGetPackSettings
{
BasePath = nupkgDir,
OutputDirectory = nugetDir
};
NuGetPack(nuspecFile, packSettings);
});
// Pushes the NuGet package to nuget.org
Task("Push")
.IsDependentOn("Pack")
.Does(() =>
{
var doc = XDocument.Load(nuspecFile);
var ns = XNamespace.Get("http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd");
string version = doc.Root.Element(ns + "metadata").Element(ns + "version").Value;
string package = $"{nugetDir}/{nugetId}.{version}.nupkg";
NuGetPush(package, new NuGetPushSettings());
});
/////////////
// Targets //
/////////////
Task("Default")
.IsDependentOn("Test");
///////////////
// Execution //
///////////////
RunTarget(target);