-
Notifications
You must be signed in to change notification settings - Fork 175
/
build.cake
136 lines (113 loc) · 4.66 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
var target = Argument("target", "Default");
var platform = Argument("platform", "AnyCPU");
var configuration = Argument("configuration", "Release");
var editbin86 = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX64\x86\editbin.exe";
var editbin64 = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX64\x64\editbin.exe";
var artifactsDir = (DirectoryPath)Directory("./artifacts");
var zipRootDir = artifactsDir.Combine("zips");
var fileZipSuffix = ".zip";
var netCoreAppsRoot= ".";
var netCoreApp = "ILSpy";
var buildDirs =
GetDirectories($"{netCoreAppsRoot}/**/bin/**")
GetDirectories($"{netCoreAppsRoot}/**/obj/**")
GetDirectories($"{netCoreAppsRoot}/artifacts/*");
var netCoreProject = new {
Path = $"{netCoreAppsRoot}/{netCoreApp}",
Name = netCoreApp,
Framework = XmlPeek($"{netCoreAppsRoot}/{netCoreApp}/{netCoreApp}.csproj", "//*[local-name()='TargetFramework']/text()"),
Runtimes = XmlPeek($"{netCoreAppsRoot}/{netCoreApp}/{netCoreApp}.csproj", "//*[local-name()='RuntimeIdentifiers']/text()").Split(';')
};
Task("Clean")
.Does(()=>{
CleanDirectories(buildDirs);
});
Task("Restore-NetCore")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetCoreRestore(netCoreProject.Path);
});
Task("Build-NetCore")
.IsDependentOn("Restore-NetCore")
.Does(() =>
{
Information("Building: {0}", netCoreProject.Name);
DotNetCoreBuild(netCoreProject.Path, new DotNetCoreBuildSettings {
Configuration = configuration
});
});
Task("Publish-NetCore")
.IsDependentOn("Restore-NetCore")
.Does(() =>
{
foreach(var runtime in netCoreProject.Runtimes)
{
var outputDir = artifactsDir.Combine(runtime);
Information("Publishing: {0}, runtime: {1}", netCoreProject.Name, runtime);
DotNetCorePublish(netCoreProject.Path, new DotNetCorePublishSettings {
Framework = netCoreProject.Framework,
Configuration = configuration,
Runtime = runtime,
SelfContained = true,
OutputDirectory = outputDir.FullPath
});
if (IsRunningOnWindows() && (runtime == "win7-x86" || runtime == "win7-x64"))
{
Information("Patching executable subsystem for: {0}, runtime: {1}", netCoreProject.Name, runtime);
var editbin = runtime == "win7-x86"? editbin86: editbin64;
if (FileExists(editbin))
{
var targetExe = outputDir.CombineWithFilePath(netCoreProject.Name ".exe");
var exitCodeWithArgument = StartProcess(editbin, new ProcessSettings {
Arguments = "/subsystem:windows " targetExe.FullPath
});
Information("The editbin command exit code: {0}", exitCodeWithArgument);
}
else
{
Information("editbin for {0}, runtime: {1} does not exist", netCoreProject.Name, runtime);
}
}
}
});
Task("Package-Mac")
.IsDependentOn("Publish-NetCore")
.Does(() =>
{
var runtimeIdentifiers = netCoreProject.Runtimes.Where(r => r.StartsWith("osx"));
foreach(var runtime in runtimeIdentifiers)
{
var workingDir = artifactsDir.Combine(runtime);
var tempDir = artifactsDir.Combine("app");
Information("Copying Info.plist");
EnsureDirectoryExists(tempDir.Combine("Contents"));
MoveFiles(workingDir.Combine("Info.plist").FullPath, tempDir.Combine("Contents"));
Information("Copying App Icons");
EnsureDirectoryExists(tempDir.Combine("Contents/Resources"));
MoveFiles(workingDir.Combine("ILSpy.icns").FullPath, tempDir.Combine("Contents/Resources"));
Information("Copying executables");
MoveDirectory(workingDir, tempDir.Combine("Contents/MacOS"));
Information("Finish packaging");
EnsureDirectoryExists(workingDir);
MoveDirectory(tempDir, workingDir.Combine($"{netCoreProject.Name}.app"));
}
});
Task("Zip-NetCore")
.IsDependentOn("Publish-NetCore")
.IsDependentOn("Package-Mac")
.Does(() =>
{
EnsureDirectoryExists(zipRootDir);
foreach(var runtime in netCoreProject.Runtimes)
{
var workingDir = artifactsDir.Combine(runtime);
Information("Zipping {0} artifacts to {1}", runtime, zipRootDir);
Zip(workingDir.FullPath, zipRootDir.CombineWithFilePath(netCoreProject.Name "-" runtime "-" configuration fileZipSuffix));
}
});
Task("Default")
.IsDependentOn("Restore-NetCore")
.IsDependentOn("Publish-NetCore")
.IsDependentOn("Zip-NetCore");
RunTarget(target);