Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions IntelliTect.Utilities/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.IO;
using System.Reflection;

namespace IntelliTect.Utilities
{
/// <summary>
/// Information about the executing assembly.
/// </summary>
public static class AssemblyInfo
{
private static DateTime? _Date;

/// <summary>
/// Gets the linker date from the assembly header.
/// </summary>
public static DateTime Date
{
get
{
if (_Date == null)
{
_Date = GetLinkerTime(Assembly.GetExecutingAssembly());
}
return _Date.Value;
}
}

/// <summary>
/// Gets the linker date of the assembly.
/// </summary>
/// <param name="assembly"></param>
/// <returns></returns>
/// <remarks>https://blog.codinghorror.com/determining-build-date-the-hard-way/</remarks>
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;
}
}
}
7 changes: 6 additions & 1 deletion IntelliTect.Utilities/IntelliTect.Utilities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IntelliTect.Utilities</RootNamespace>
<AssemblyName>IntelliTect.Utilities</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -40,7 +41,11 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="IntelliTect.Utilities.nuspec" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
17 changes: 17 additions & 0 deletions IntelliTect.Utilities/IntelliTect.Utilities.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<licenseUrl>https://github.com/IntelliTect/IntelliTect/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/IntelliTect/IntelliTect</projectUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Added assembly linker date.</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>IntelliTect</tags>
</metadata>
</package>
4 changes: 2 additions & 2 deletions IntelliTect.Utilities/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down