forked from CubeCoders/ConfuserEx-Reborn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateVersion.cs
54 lines (49 loc) · 1.46 KB
/
UpdateVersion.cs
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
using System;
using System.Diagnostics;
using System.IO;
public static class Program {
public static int Main(string[] args) {
if (args.Length != 1) {
Console.WriteLine("invalid argument length.");
return -1;
}
string dir = args[0];
string ver = File.ReadAllText(Path.Combine(dir, "VERSION"));
string tag = null;
string gitDir = Path.Combine(dir, ".git");
if (!Directory.Exists(gitDir)) {
Console.WriteLine("git repository not found.");
}
else {
try {
var info = new ProcessStartInfo("git", "describe");
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
using (Process ps = Process.Start(info)) {
tag = ps.StandardOutput.ReadLine();
string[] infos = tag.Split('-');
if (infos.Length >= 3)
ver = ver + "." + infos[infos.Length - 2];
else
ver = infos[0].Substring(1);
ps.WaitForExit();
if (ps.ExitCode != 0) {
Console.WriteLine("error when executing git describe: " + ps.ExitCode);
}
}
}
catch {
Console.WriteLine("error when executing git describe.");
}
}
tag = tag ?? "v" + ver + "-custom";
string template = Path.Combine(dir, "GlobalAssemblyInfo.Template.cs");
string output = Path.Combine(dir, "GlobalAssemblyInfo.cs");
string verInfo = File.ReadAllText(template);
verInfo = verInfo.Replace("{{VER}}", ver);
verInfo = verInfo.Replace("{{TAG}}", tag);
File.WriteAllText(output, verInfo);
Console.WriteLine("Version updated.");
return 0;
}
}