blob: e40eb782b5da7fcca93a1872c1d21898f6ce879a (
plain)
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;
using System.IO;
namespace DotNetOpenAuth.BuildTasks {
public class GetBuildVersion : Task {
/// <summary>
/// Gets the version string to use in the compiled assemblies.
/// </summary>
[Output]
public string Version { get; private set; }
/// <summary>
/// The file that contains the version base (Major.Minor.Build) to use.
/// </summary>
[Required]
public string VersionFile { get; set; }
public override bool Execute() {
try {
Version typedVersion = ReadVersionFromFile();
typedVersion = new Version(typedVersion.Major, typedVersion.Minor, typedVersion.Build, CalculateJDate(DateTime.Now));
Version = typedVersion.ToString();
} catch (ArgumentOutOfRangeException ex) {
Log.LogErrorFromException(ex);
return false;
}
return true;
}
private Version ReadVersionFromFile() {
string[] lines = File.ReadAllLines(VersionFile);
string versionLine = lines[0];
return new Version(versionLine);
}
private int CalculateJDate(DateTime date) {
int yearLastDigit = date.Year % 10;
DateTime firstOfYear = new DateTime(date.Year, 1, 1);
int dayOfYear = (date - firstOfYear).Days + 1;
int jdate = yearLastDigit * 1000 + dayOfYear;
return jdate;
}
}
}
|