This does the trick for our web application, though that is tightly
controlled. If someone modified your files, this code would be fooled.
(Your assembly could have come from someplace besides a file, like the
web, so this snippet won't tell you the 'build date' of such an
assembly, if it's even knowable.)
private static string AssemblyInfo(Type t)
{
const string fileUrlPrefix = "file:///";
Assembly a = Assembly.GetAssembly(t);
AssemblyName aName = a.GetName();
string aUrl = aName.CodeBase;
DateTime aCreated = DateTime.MinValue;
if (aUrl.IndexOf(fileUrlPrefix)==0)
aCreated =
File.GetLastWriteTime(aUrl.Substring(fileUrlPrefix.Length));
return aName.Version.ToString() + (aCreated == DateTime.MinValue
? "" : (", build date: " + aCreated.ToString() ));
}
Sebastian Good
http://www.palladiumconsulting.com/
Palladium Consulting Inc.
-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Kristoffer
Sheather
Sent: Monday, January 24, 2005 9:39 PM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] Determing time when a assembly was built
Check the date/time stamp on the files?
-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Raj Malli
Sent: Tuesday, 25 January 2005 13:31
To: [email protected]
Subject: [ADVANCED-DOTNET] Determing time when a assembly was built
Hi guys
Is there a way by which I can programmatically determine the build time
of an assembly? I would like to show the following information in the
"About" box of my application: Application Name, Version and Build Time.
I do not want to do the following:
- Use the last two parts of the assembly version to encode the time
- Get the last modified time from the assembly file using (say) the
FileInfo class
In C/C++, this is how I'd have done this:
#define BUILD_TIME __TIME__
void OnAbout() {
...
MessageBox(BUILD_TIME);
...
}
I know C# supports a preprocessor. Can I do something similar to the
above in C#? Otherwise what other options do I have?
Thanks
Raj
===================================
This list is hosted by DevelopMentor(r) http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
Notice:
The information contained in this e-mail message and any attached files
may be confidential information, and may also be the subject of legal
professional privilege. If you are not the intended recipient any use,
disclosure or copying of this e-mail is unauthorised. If you have
received this e-mail in error, please notify the sender immediately by
reply e-mail and delete all copies of this transmission together with
any attachments.
===================================
This list is hosted by DevelopMentorR http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
===================================
This list is hosted by DevelopMentor� http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com