-
Notifications
You must be signed in to change notification settings - Fork 11
/
parameters.cake
70 lines (57 loc) · 2.16 KB
/
parameters.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
#tool "nuget:?package=GitVersion.CommandLine"
#tool "nuget:?package=vswhere"
#addin "Cake.Git"
public class BuildParameters
{
public string Target { get; private set; }
public string SolutionBuildConfiguration { get; private set; }
public string Version { get; private set; }
public string FullVersion { get; private set; }
public string AssemblyVersion { get; private set;}
public FilePath MSBuildPath {get; private set;}
public static BuildParameters GetParameters(ICakeContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
var target = context.Argument("target", "Default");
var solutionBuildConfiguration = context.Argument("SolutionBuildConfiguration", "Release");
var vsLatest = context.VSWhereLatest();
if (vsLatest == null)
{
throw new InvalidOperationException("MSBuild not found.");
}
var msBuildPath = vsLatest.CombineWithFilePath("./MSBuild/15.0/Bin/amd64/MSBuild.exe");
var logFilePath = context.MakeAbsolute(context.File("gitVersion.log")).FullPath;
var gitVersionSettings = new GitVersionSettings
{
WorkingDirectory = context.Directory(System.IO.Directory.GetCurrentDirectory()),
LogFilePath = context.File(logFilePath)
};
GitVersion gitVersion;
try
{
gitVersion = context.GitVersion(gitVersionSettings);
} catch
{
var logs = System.IO.File.ReadAllLines(logFilePath);
foreach (var log in logs)
{
context.Information(log);
}
throw;
}
context.Information("Semantic Version: " + gitVersion.SemVer);
context.Information("Full version: " + gitVersion.FullSemVer);
return new BuildParameters
{
Target = target,
SolutionBuildConfiguration = solutionBuildConfiguration,
MSBuildPath = msBuildPath,
FullVersion = gitVersion.FullSemVer,
AssemblyVersion = gitVersion.AssemblySemVer,
Version = gitVersion.SemVer
};
}
}