forked from TEdit/Terraria-Map-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDateStampVersion.tasks
57 lines (49 loc) · 2.36 KB
/
DateStampVersion.tasks
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
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Go" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="RegexTransform" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<Items ParameterType="Microsoft.Build.Framework.ITaskItem[]" />
<Vers ParameterType="System.String" Required="False" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Text.RegularExpressions" />
<Using Namespace="Microsoft.Build.Framework" />
<Code Type="Fragment" Language="cs">
<![CDATA[
// Generate Version Numbers
string datedBuildNumber = string.Format("{0}{1:000}", DateTime.Now.ToString("yy"), DateTime.Now.DayOfYear);
string revisionNumber = !string.IsNullOrWhiteSpace(Vers) ? Vers : DateTime.Now.ToString("HHmm");
foreach (ITaskItem item in Items)
{
// Find Current Version in file
string fileName = item.GetMetadata("FullPath");
string findAssmVers = @"AssemblyVersion\(\""(?<major>\d+)\.(?<minor>\d+)\.(?<build>\d+)\.(?<revision>\d+)";
string findAssmFileVers = @"AssemblyFileVersion\(\""(?<major>\d+)\.(?<minor>\d+)\.(?<build>\d+)\.(?<revision>\d+)";
if (!File.Exists(fileName))
{
Log.LogError(null, null, null, null, 0, 0, 0, 0, String.Format("Could not find version file: {0}", fileName), new object[0]);
}
string content = File.ReadAllText(fileName);
var m = Regex.Match(content, findAssmVers);
// Generate new Version Numbers
string assmVers = string.Format("AssemblyVersion(\"{0}.{1}.0.0",
m.Groups["major"].Value,
m.Groups["minor"]);
string assmFileVers = string.Format(
"AssemblyFileVersion(\"{0}.{1}.{2}.{3}",
m.Groups["major"].Value,
m.Groups["minor"].Value,
datedBuildNumber,
0);
// Write new version numbers
string result = Regex.Replace(content, findAssmVers, assmVers);
result = Regex.Replace(result, findAssmFileVers, assmFileVers);
File.WriteAllText(fileName, result);
}
]]>
</Code>
</Task>
</UsingTask>
</Project>