Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the assembly last modified date?

I want to render (for internal debugging/info) the last modified date of an assembly, so I'll know when a certain website was deployed.

Is it possible to get it through reflection?

I get the version like this:

Assembly.GetExecutingAssembly().GetName().Version.ToString();

I'm looking for something similar -- I don't want to open the physical file, get its properties, or something like that, as I'll be rendering it in the master page, and don't want that kind of overhead.

like image 885
juan Avatar asked Apr 29 '09 20:04

juan


2 Answers

I'll second pYrania's answer:

System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.FileInfo fileInfo = new System.IO.FileInfo(assembly.Location);
DateTime lastModified = fileInfo.LastWriteTime;

But add this:

You mention you don't want to access the file system since it's in your master page and you don't want to make that extra file system hit for every page. So don't, just access it once in the Application load event and then store it as an application-level variable.

like image 176
Clyde Avatar answered Oct 05 '22 00:10

Clyde


If you default the Revision and Build Numbers in AssemblyInfo:

[assembly: AssemblyVersion("1.0.*")]

You can get the an approximate build date with:

Version version = typeof(MyType).Assembly.GetName().Version;
DateTime date = new DateTime(2000, 1, 1)
    .AddDays(version.Build)
    .AddSeconds(version.Revision * 2);
like image 40
Hallgrim Avatar answered Oct 05 '22 00:10

Hallgrim