From 13f352b0b45c0d24cc54f610ff771266f024da1f Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Wed, 1 Mar 2017 16:38:29 -0800 Subject: [PATCH 1/2] Adding AssemblyInfo to get access to the linker date for the executing assembly. Adding nuspec file. --- IntelliTect.Utilities/AssemblyInfo.cs | 55 +++++++++++++++++++ .../IntelliTect.Utilities.csproj | 7 ++- .../IntelliTect.Utilities.nuspec | 17 ++++++ ...telliTect.Utilities.sln => IntelliTect.sln | 2 +- 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 IntelliTect.Utilities/AssemblyInfo.cs create mode 100644 IntelliTect.Utilities/IntelliTect.Utilities.nuspec rename IntelliTect.Utilities/IntelliTect.Utilities.sln => IntelliTect.sln (89%) diff --git a/IntelliTect.Utilities/AssemblyInfo.cs b/IntelliTect.Utilities/AssemblyInfo.cs new file mode 100644 index 0000000..399c69b --- /dev/null +++ b/IntelliTect.Utilities/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System; +using System.IO; +using System.Reflection; + +namespace IntelliTect.Utilities +{ + /// + /// Information about the executing assembly. + /// + public static class AssemblyInfo + { + private static DateTime? _Date; + + /// + /// Gets the linker date from the assembly header. + /// + public static DateTime Date + { + get + { + if (_Date == null) + { + _Date = GetLinkerTime(Assembly.GetExecutingAssembly()); + } + return _Date.Value; + } + } + + /// + /// Gets the linker date of the assembly. + /// + /// + /// + /// https://blog.codinghorror.com/determining-build-date-the-hard-way/ + private static DateTime GetLinkerTime(Assembly assembly) + { + var filePath = assembly.Location; + const int cPeHeaderOffset = 60; + const int cLinkerTimestampOffset = 8; + + var buffer = new byte[2048]; + + using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) + stream.Read(buffer, 0, 2048); + + var offset = BitConverter.ToInt32(buffer, cPeHeaderOffset); + var secondsSince1970 = BitConverter.ToInt32(buffer, offset + cLinkerTimestampOffset); + var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + + var linkTimeUtc = epoch.AddSeconds(secondsSince1970); + + return linkTimeUtc; + } + } +} \ No newline at end of file diff --git a/IntelliTect.Utilities/IntelliTect.Utilities.csproj b/IntelliTect.Utilities/IntelliTect.Utilities.csproj index 2d24e29..37399b2 100644 --- a/IntelliTect.Utilities/IntelliTect.Utilities.csproj +++ b/IntelliTect.Utilities/IntelliTect.Utilities.csproj @@ -9,8 +9,9 @@ Properties IntelliTect.Utilities IntelliTect.Utilities - v4.5.2 + v4.6.2 512 + true @@ -40,7 +41,11 @@ + + + + \ No newline at end of file diff --git a/IntelliTect.Utilities/IntelliTect.Utilities.nuspec b/IntelliTect.Utilities/IntelliTect.Utilities.nuspec new file mode 100644 index 0000000..e622049 --- /dev/null +++ b/IntelliTect.Utilities/IntelliTect.Utilities.nuspec @@ -0,0 +1,17 @@ + + + + $id$ + $version$ + $title$ + $author$ + $author$ + https://github.com/IntelliTect/IntelliTect/blob/master/LICENSE + https://github.com/IntelliTect/IntelliTect + true + $description$ + Added assembly linker date. + Copyright 2017 + IntelliTect + + \ No newline at end of file diff --git a/IntelliTect.Utilities/IntelliTect.Utilities.sln b/IntelliTect.sln similarity index 89% rename from IntelliTect.Utilities/IntelliTect.Utilities.sln rename to IntelliTect.sln index 092a9b4..564322a 100644 --- a/IntelliTect.Utilities/IntelliTect.Utilities.sln +++ b/IntelliTect.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26206.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntelliTect.Utilities", "IntelliTect.Utilities.csproj", "{6E9F4A6A-F611-4ECB-8AAC-B2079C0B9DF5}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntelliTect.Utilities", "IntelliTect.Utilities\IntelliTect.Utilities.csproj", "{6E9F4A6A-F611-4ECB-8AAC-B2079C0B9DF5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution From 678b74511f0aa4b859e526fb729e0cff29d3ab63 Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Wed, 1 Mar 2017 16:41:22 -0800 Subject: [PATCH 2/2] Adding missing description and author for the nuget --- IntelliTect.Utilities/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IntelliTect.Utilities/Properties/AssemblyInfo.cs b/IntelliTect.Utilities/Properties/AssemblyInfo.cs index 8019e40..cadaf7d 100644 --- a/IntelliTect.Utilities/Properties/AssemblyInfo.cs +++ b/IntelliTect.Utilities/Properties/AssemblyInfo.cs @@ -6,9 +6,9 @@ // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("IntelliTect.Utilities")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyDescription("A utility library for IntelliTect")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] +[assembly: AssemblyCompany("IntelliTect")] [assembly: AssemblyProduct("IntelliTect.Utilities")] [assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyTrademark("")]