-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.cake
110 lines (88 loc) · 3.07 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
#tool nuget:?package=vswhere&version=3.1.7
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("build-target", "Default");
var version = Argument("build-version", EnvironmentVariable("BUILD_NUMBER") ?? "1.0.0");
var configuration = Argument("build-configuration", "Release");
var apiKey = Argument("api-key", "");
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
MSBuildSettings msPackSettings;
DotNetMSBuildSettings dnBuildSettings;
DotNetPackSettings dnPackSettings;
private void PackDotnet(string filePath)
{
DotNetPack(filePath, dnPackSettings);
}
private void PackMSBuild(string filePath)
{
MSBuild(filePath, msPackSettings);
}
private bool GetMSBuildWith(string requires)
{
if (IsRunningOnWindows())
{
DirectoryPath vsLatest = VSWhereLatest(new VSWhereLatestSettings { Requires = requires });
if (vsLatest != null)
{
var files = GetFiles(vsLatest.FullPath + "/**/MSBuild.exe");
if (files.Any())
{
msPackSettings.ToolPath = files.First();
return true;
}
}
}
return false;
}
var NuGetToolPath = Context.Tools.Resolve ("nuget.exe");
var RunProcess = new Action<FilePath, string> ((process, args) =>
{
var result = StartProcess (process, args);
if (result != 0) {
throw new Exception ($"Process '{process}' failed with error: {result}");
}
});
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Prep")
.Does(() =>
{
Console.WriteLine("Build Version: {0}", version);
msPackSettings = new MSBuildSettings();
msPackSettings.Verbosity = Verbosity.Minimal;
msPackSettings.Configuration = configuration;
msPackSettings.Restore = true;
msPackSettings.WithProperty("Version", version);
msPackSettings.WithTarget("Pack");
dnBuildSettings = new DotNetMSBuildSettings();
dnBuildSettings.WithProperty("Version", version);
dnPackSettings = new DotNetPackSettings();
dnPackSettings.MSBuildSettings = dnBuildSettings;
dnPackSettings.Verbosity = DotNetVerbosity.Minimal;
dnPackSettings.Configuration = configuration;
});
Task("Build")
.IsDependentOn("Prep")
.WithCriteria(() => IsRunningOnWindows())
.Does(() =>
{
DotNetRestore("ImeSharp/ImeSharp.csproj");
PackDotnet("ImeSharp/ImeSharp.csproj");
});
Task("Default")
.IsDependentOn("Build");
Task("Publish")
.IsDependentOn("Default")
.Does(() =>
{
var args = $"push -Source \"https://api.nuget.org/v3/index.json\" -ApiKey {apiKey} Artifacts/WinForms/Release/ImeSharp.{version}.nupkg";
RunProcess(NuGetToolPath, args);
});
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);