forked from XamlAnimatedGif/XamlAnimatedGif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
178 lines (160 loc) · 4.39 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
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[]
{
new { Name = $"{projectName}.Wpf", MSBuildPlatform = MSBuildPlatform.Automatic },
new { Name = $"{projectName}.Wpf.4.0", MSBuildPlatform = MSBuildPlatform.Automatic },
new { Name = $"{projectName}.WinRT", MSBuildPlatform = MSBuildPlatform.Automatic },
new { Name = $"{projectName}.Silverlight", MSBuildPlatform = MSBuildPlatform.x86 }
};
var projectDirsToClean = new[] { "bin", "obj", "AppPackages" };
// 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",
$"{projectName}.Wpf/bin/{configuration}/{projectName}.pdb"
}
},
new
{
Name = "net40",
Files = new[]
{
$"{projectName}.Wpf.4.0/bin/{configuration}/{projectName}.dll",
$"{projectName}.Wpf.4.0/bin/{configuration}/{projectName}.pdb"
}
},
new
{
Name = "portable-win81+wpa81",
Files = new[]
{
$"{projectName}.WinRT/bin/{configuration}/{projectName}.dll",
$"{projectName}.WinRT/bin/{configuration}/{projectName}.pdb"
}
},
new
{
Name = "sl5",
Files = new[]
{
$"{projectName}.Silverlight/bin/{configuration}/{projectName}.dll",
$"{projectName}.Silverlight/bin/{configuration}/{projectName}.pdb"
}
},
};
//////////////////////
// Setup / Teardown //
//////////////////////
Setup(context =>
{
// Executed BEFORE the first task.
Information("Running tasks...");
});
Teardown(context =>
{
// 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.Name}/{d}";
CleanDirectories(dirsToClean);
CleanDirectory(nugetDir);
});
// Restores NuGet packages
Task("Restore")
.Does(() =>
{
NuGetRestore(solutionFile);
});
// Builds the solution
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
foreach (var project in projects)
{
MSBuild(
$"{project.Name}/{project.Name}.csproj",
settings => settings.SetMSBuildPlatform(project.MSBuildPlatform)
.SetConfiguration(configuration));
}
});
// Creates the NuGet package
Task("Pack")
.IsDependentOn("Build")
.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,
Symbols = true
};
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("Build");
///////////////
// Execution //
///////////////
RunTarget(target);