Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Saturday, February 13, 2010 11:40 PM
Hey,
Is it possible to get the actual compile date of an assembly? I'd like to be able to get it, so users can see how old the build is they are using. I tried simply getting the file creation date, but that won't work when using an installer, since the file will then be created when the app is installed.
Cheers!
Jeroen De Dauw
All replies (4)
Sunday, February 14, 2010 1:49 AM âś…Answered | 1 vote
Yes it is possible to retrieve the build date of an assembly. There are a couple ways that I know of; the following article outlines the two way I am aware of doing so: http://stackoverflow.com/questions/1600962/c-displaying-the-build-date
Sunday, February 14, 2010 12:04 AM | 1 vote
Hi,
> Is it possible to get the actual compile date of an assembly?
Not as far as I know (there's no .NET API for that).
> I'd like to be able to get it, so users can see how old the build is they are using.
You could use a pre-build action to serialize your own info class to file and embedd the serialized file as a resource in your application.
Or, you could use the assembly version number. I remember a VS-add-in, I think it was called Build Version Increment, that had many versioning styles, inlcuding the option to integrate the date into the version number.
Marcel
Thursday, January 31, 2019 2:44 PM | 1 vote
File.GetCreationTime(GetType().Assembly.Location)
Microsoft Community Contributor
Monday, December 2, 2019 9:47 PM
After looking over this post and having to make my own solution, I came up with this extension method (used in .NET Core 2.2, but it should work in most other versions).
public static class ReflectionExtension
{
public static DateTimeOffset? GetBuildDateTime(this Assembly assembly)
{
var path = assembly.GetName().CodeBase;
if (path.StartsWith(@"file:///"))
{
path = path.Substring(8);
}
if (File.Exists(path))
{
return new DateTimeOffset(File.GetCreationTimeUtc(path));
}
return null;
}
}
Then to call it I used this...
var buildTime = Assembly.GetAssembly(this.GetType()).GetBuildDateTime();
Maybe this will help someone out there