generated from wazzamatazz/csharp-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
144 lines (114 loc) · 4.53 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
const string DefaultSolutionName = "./Jaahas.MSBuild.Extensions.sln";
///////////////////////////////////////////////////////////////////////////////////////////////////
// COMMAND LINE ARGUMENTS:
//
// --project=<PROJECT OR SOLUTION>
// The MSBuild project or solution to build.
// Default: see DefaultSolutionName constant above.
//
// --target=<TARGET>
// Specifies the Cake target to run.
// Default: Test
// Possible Values: Clean, Restore, Build, Pack
//
// --configuration=<CONFIGURATION>
// Specifies the MSBuild configuration to use.
// Default: Debug
//
// --clean
// Specifies if this is a rebuild rather than an incremental build. All artifact and bin folders
// will be cleaned prior to running the specified target.
//
// --ci
// Forces continuous integration build mode. Not required if the build is being run by a
// supported continuous integration build system.
//
// --verbose
// Enables verbose messages.
//
///////////////////////////////////////////////////////////////////////////////////////////////////
#addin nuget:?package=Cake.Git&version=1.0.0
#load "build/build-state.cake"
#load "build/build-utilities.cake"
// Get the target that was specified.
var target = Argument("target", "Pack");
///////////////////////////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////////////////////////
// Constructs the build state object.
Setup<BuildState>(context => {
try {
BuildUtilities.WriteTaskStartMessage(BuildSystem, "Setup");
var state = new BuildState() {
SolutionName = Argument("project", DefaultSolutionName),
Target = target,
Configuration = Argument("configuration", "Debug"),
ContinuousIntegrationBuild = HasArgument("ci") || !BuildSystem.IsLocalBuild,
Clean = HasArgument("clean"),
Verbose = HasArgument("verbose")
};
if (!string.Equals(state.Target, "Clean", StringComparison.OrdinalIgnoreCase)) {
BuildUtilities.WriteBuildStateToLog(BuildSystem, state);
}
return state;
}
finally {
BuildUtilities.WriteTaskEndMessage(BuildSystem, "Setup");
}
});
// Pre-task action.
TaskSetup(context => {
BuildUtilities.WriteTaskStartMessage(BuildSystem, context.Task.Name);
});
// Post task action.
TaskTeardown(context => {
BuildUtilities.WriteTaskEndMessage(BuildSystem, context.Task.Name);
});
///////////////////////////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////////////////////////
// Cleans up artifact and bin folders.
Task("Clean")
.WithCriteria<BuildState>((c, state) => state.RunCleanTarget)
.Does<BuildState>(state => {
foreach (var pattern in new [] { $"./src/**/bin/{state.Configuration}", "./artifacts/**", "./**/TestResults/**" }) {
BuildUtilities.WriteLogMessage(BuildSystem, $"Cleaning directories: {pattern}");
CleanDirectories(pattern);
}
});
// Restores NuGet packages.
Task("Restore")
.Does<BuildState>(state => {
DotNetCoreRestore(state.SolutionName);
});
// Builds the solution.
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does<BuildState>(state => {
var buildSettings = new DotNetCoreBuildSettings {
Configuration = state.Configuration,
NoRestore = true,
MSBuildSettings = new DotNetCoreMSBuildSettings()
};
buildSettings.MSBuildSettings.Targets.Add(state.Clean ? "Rebuild" : "Build");
BuildUtilities.ApplyMSBuildProperties(buildSettings.MSBuildSettings, state);
DotNetCoreBuild(state.SolutionName, buildSettings);
});
// Builds NuGet packages.
Task("Pack")
.IsDependentOn("Build")
.Does<BuildState>(state => {
var buildSettings = new DotNetCorePackSettings {
Configuration = state.Configuration,
NoRestore = true,
NoBuild = true,
MSBuildSettings = new DotNetCoreMSBuildSettings()
};
BuildUtilities.ApplyMSBuildProperties(buildSettings.MSBuildSettings, state);
DotNetCorePack(state.SolutionName, buildSettings);
});
///////////////////////////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////////////////////////
RunTarget(target);