Can I translate .net assembly versions to dates?

In Roslyn and .NET Core, the compiler source code is now available.

The file roslyn/src/Compilers/Core/Portable/VersionHelper.cs ( https://github.com/dotnet/roslyn/blob/614299ff83da9959fa07131c6d0ffbc58873b6ae/src/Compilers/Core/Portable/VersionHelper.cs - from commit 4f44984 on 2016-04-19 ) does have the same date logic from the original csc in the method GenerateVersionFromPatternAndCurrentTime:

int revision = (int)time.TimeOfDay.TotalSeconds / 2;

// 24 * 60 * 60 / 2 = 43200 < 65535
Debug.Assert(revision < ushort.MaxValue);

// ...

TimeSpan days = time.Date - new DateTime(2000, 1, 1);
int build = Math.Min(ushort.MaxValue, (int)days.TotalDays);

return new Version(pattern.Major, pattern.Minor, (ushort)build, (ushort)revision);

However the documentation comments simply say "a time-based value" without being specific about how it's generated.

But indeed, so far the Build is still days since 2000-01-01 and Revision is half the number of seconds since midnight.

Interestingly, this behavior is defined and verified in the test cases in VersionHelperTests.cs: https://github.com/dotnet/roslyn/blob/614299ff83da9959fa07131c6d0ffbc58873b6ae/src/Compilers/Core/CodeAnalysisTest/VersionHelperTests.cs


The version string has this format:

<major version>.<minor version>.<build number>.<revision>

and if you set the version as you've described, to 1.0.*:

The result of this is a build number set to the number of days since a random, designated start date and the revision based on the number of seconds since midnight.

The key here is "random". So, you can translate the revision to a time of day, but it sounds like you won't be able to resolve it to a date.

http://msdn.microsoft.com/en-us/library/ms998223.aspx


The AssemblyVersionAttribute documentation states that:

The default build number increments daily. The default revision number is the number of seconds since midnight local time (without taking into account time zone adjustments for daylight saving time), divided by 2.

The reference date for the build number isn't specified. In practice, I've found this to be 1 January 2000.

The date can therefore be reconstructed as follows:

var result = new DateTime(2000, 1, 1);
result = result.AddDays(buildNumber);
result = result.AddSeconds(revision * 2);

Since the reference date isn't documented, it can't be guaranteed to always remain unchanged.


According to MSDN: "The default build number increments daily. The default revision number is random."

If you look at the source for AssemblyVersionAttribute in reflector, you will see it's not doing anything at all, just accepting the string. So the magic happens with the compiler itself, which as far as I can tell is not documented anywhere. "Incremented everyday" is pretty vague, starting from what point?

I wouldn't expect to be able to use these versions with any reliability. It is probably better to base your version off of a label in a source control system or something like that.

Tags:

.Net