-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.cake
57 lines (49 loc) · 1.38 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
#addin nuget:?package=Cake.Git&version=5.0.1
#addin nuget:?package=Cake.FileHelpers&version=7.0.0
var target = Argument("target", "Build");
var configuration = Argument("configuration", "Release");
Task("Restore")
.Does(() =>
{
// 运行 dotnet restore
DotNetRestore("./AquaMai.sln");
});
Task("PreBuild")
.Does(() =>
{
var gitDescribe = GitDescribe(".", GitDescribeStrategy.Tags).Substring(1); // 获取 git describe 的输出
var buildDate = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");
var shortVers = gitDescribe.Split('-');
string shortVer;
if (shortVers.Length > 1)
{
shortVer = $"{shortVers[0]}.{shortVers[1]}";
}
else
{
shortVer = shortVers[0];
}
var versionContent = $@"
// Auto-generated file. Do not modify manually.
namespace AquaMai;
public static partial class BuildInfo
{{
public const string Version = ""{shortVer}"";
public const string GitVersion = ""{gitDescribe}"";
public const string BuildDate = ""{buildDate}"";
}}
";
FileWriteText("./AquaMai/BuildInfo.g.cs", versionContent);
});
Task("Build")
.IsDependentOn("PreBuild")
.IsDependentOn("Restore")
.Does(() =>
{
// 使用 dotnet build 进行构建
DotNetBuild("./AquaMai.sln", new DotNetBuildSettings
{
Configuration = configuration
});
});
RunTarget(target);