473,327 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Getting date of assembly compilation

Hi,

Is there a way of getting the date that an assembly was last compiled? I
am trying to help myself to remember what version of a particular
assembly my Web applications are using, so I've taken to having it
output the version number at the bottom of the page using:

Assembly a = Assembly.GetExecutingAssembly();
AssemblyName an = a.GetName();
info.InnerHtml = "Powered by " + Info.Name + " v" + an.Version;

But it would be nice if I could have the date shown too so that I can
remember when I actually compiled that particular version.

Cheers,

--
Dylan Parry
http://electricfreedom.org -- Where the Music Progressively Rocks!
Jun 13 '06 #1
2 3786
Dylan Parry wrote:
Is there a way of getting the date that an assembly was last compiled? I
am trying to help myself to remember what version of a particular
assembly my Web applications are using, so I've taken to having it
output the version number at the bottom of the page using:


If you let the compiler generate revision and build numbers for you
(e.g. by setting the Version number to "1.0.*" in AssemblyInfo.cs) then
the Build number of the Assembly's Version property is simply the
number of days since 1/1/2000.

You can use this at runtime to determine when it was built:

using System.Reflection;

...

DateTime baseDate = new DateTime(2000, 1, 1);
Version ver = Assembly.GetExecutingAssembly().GetName().Version;
DateTime buildDate = baseDate.AddDays(ver.Build);

Matt

Jun 13 '06 #2
I was not satisfied with the automatic version numbering that VS.Net provided, so I wrote a small app that parsed AssemblyInfo.cs to increment the build number for me (only on successful builds). I invoke that utility in the Post-build event. You could do a similar thing (invoked in the Pre-build event) that parses the source and injects today's date - perhaps into a custom assembly-level attribute (but just as simply into the initializer of a string constant).

Running utilities and parsing files may be "so 20th century" - but it works. :)

You could be even more crude and it would work:
In FileA:
using system;
namespace nsAssemblyBuildDate {
static class CAssemblyBuildDate {
private static string strAssemblyBuildDate = "

In FileB:
";
public static Date AssemblyBuildDate { get { return strAssemblyBuildDate.Trim(); } }
} }

in Post-build event:
type FileA > AssemblyBuildDate.cs
date /t >> AssemblyBuildDate.cs
type FileB >> AssemblyBuildDate.cs
HTH,
Chris

--
Chris Trelawny-Ross

"Dylan Parry" <us****@dylanparry.com> wrote in message news:68***************@dylanparry.com...
Hi,

Is there a way of getting the date that an assembly was last compiled? I
am trying to help myself to remember what version of a particular
assembly my Web applications are using, so I've taken to having it
output the version number at the bottom of the page using:

Assembly a = Assembly.GetExecutingAssembly();
AssemblyName an = a.GetName();
info.InnerHtml = "Powered by " + Info.Name + " v" + an.Version;

But it would be nice if I could have the date shown too so that I can
remember when I actually compiled that particular version.

Cheers,

--
Dylan Parry
http://electricfreedom.org -- Where the Music Progressively Rocks!
Jun 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Michael A. Covington | last post by:
Is there a way to make a C# program print the date on which it was compiled? Finding the file date of the executable is one way, but it's not foolproof. Thanks!
4
by: karunakar | last post by:
Hi All I was poplating Datagrid Datagrid has one of the column showing datetime field format iam showing DATE here not Necessary to populate the Time Frame Even my datebase column also...
3
by: Just D. | last post by:
We all know hot to get the Assembly name and version. Can we get the assembly compilation date and how can we get this datetime if it's possible? It's not a very good idea to get the file DateTime...
3
by: Jesper | last post by:
Hi, In c++ ( I do no longer remember exactly how) I used some compiler predefined macro to insert the date and time of compilation into a string. How is this done in c# In c++ it could have...
11
by: Wolfgang Kaml | last post by:
I am not sure if this is more of an expert question, but I am sure that they are out there. I'd like to setup a general application or bin directory on my Win2003.Net Server that will hold some...
2
by: William Gower | last post by:
I am trying to display a page that has a data grid on it. I get this message Description: An error occurred during the processing of a configuration file required to service this request....
2
by: john | last post by:
Maybe I haven't had that "a-ha" moment yet, but I think the new approach to web projects is a step in the wrong direction. My main beef is that control over the assembly generation process has...
0
by: qiang | last post by:
Hi everyone, Could you please take a look at an exception for ASP.NET application? My ASP.NET application is using Infragistics WebChart control. I encounter an exception below when...
7
by: R Reyes | last post by:
Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? I'm trying to manipulate MS Word from my Web Form application and I can't get passed...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.