Last active
November 1, 2019 09:52
-
-
Save oledid/00c609261b9440b6645d106f03d01118 to your computer and use it in GitHub Desktop.
BuildDateAttribute - get build-date in build for cache-busting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.meziantou.net/getting-the-date-of-build-of-a-dotnet-assembly-at-runtime.htm | |
using System; | |
using System.Globalization; | |
namespace Core | |
{ | |
[AttributeUsage(AttributeTargets.Assembly)] | |
public class BuildDateAttribute : Attribute | |
{ | |
public BuildDateAttribute(string value) | |
{ | |
DateTime = DateTime.ParseExact(value, "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.None); | |
} | |
public DateTime DateTime { get; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- [...] --> | |
<ItemGroup> | |
<AssemblyAttribute Include="Core.BuildDateAttribute"> | |
<_Parameter1>$([System.DateTime]::UtcNow.ToString("yyyyMMddHHmmss"))</_Parameter1> | |
</AssemblyAttribute> | |
</ItemGroup> | |
<!-- [...] --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment