422,351 Members | 1,447 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,351 IT Pros & Developers. It's quick & easy.

Make a C# program print its compilation date?

P: n/a
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!
Nov 15 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Not as far as I know. I had to solve it using the following elaborate
technic:

create a small program that reads the date and time using DateTime.Now and
serializes it into a small file. This program is exucute just before the
compilation of my main program. The generated serialized file is then
included in the application as an embedded resouce. Then in the program I
read this resource and deserialize to get the compilation date and time
back...

It's a lot of work, but ik works.
Hope this helps.

"Michael A. Covington" <Mi*****@CovingtonInnovations.com> wrote in message
news:OK*************@TK2MSFTNGP09.phx.gbl...
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!

Nov 15 '05 #2

P: n/a
Not as far as I know. I had to solve it using the following elaborate
technic:

create a small program that reads the date and time using DateTime.Now and
serializes it into a small file. This program is exucute just before the
compilation of my main program. The generated serialized file is then
included in the application as an embedded resouce. Then in the program I
read this resource and deserialize to get the compilation date and time
back...

It's a lot of work, but ik works.
Hope this helps.

"Michael A. Covington" <Mi*****@CovingtonInnovations.com> wrote in message
news:OK*************@TK2MSFTNGP09.phx.gbl...
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!

Nov 15 '05 #3

P: n/a
I saw somebody create a VS addin that sets the last two parts of the
assembly version to the date and time right before a build. I can't find it
now, but that would be another way (since you can pull up the assembly
version pretty easily in code). Plus it's kindof handy if you need to know
when you made a build just by looking at the version number of the .dll /
..exe

If I find it, I'll post a link here.

mike

"Jeroen Smits" <sm***@bc-br.com> wrote in message
news:u8*************@TK2MSFTNGP10.phx.gbl...
Not as far as I know. I had to solve it using the following elaborate
technic:

create a small program that reads the date and time using DateTime.Now and
serializes it into a small file. This program is exucute just before the
compilation of my main program. The generated serialized file is then
included in the application as an embedded resouce. Then in the program I
read this resource and deserialize to get the compilation date and time
back...

It's a lot of work, but ik works.
Hope this helps.

"Michael A. Covington" <Mi*****@CovingtonInnovations.com> wrote in message
news:OK*************@TK2MSFTNGP09.phx.gbl...
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!


Nov 15 '05 #4

P: n/a
I saw somebody create a VS addin that sets the last two parts of the
assembly version to the date and time right before a build. I can't find it
now, but that would be another way (since you can pull up the assembly
version pretty easily in code). Plus it's kindof handy if you need to know
when you made a build just by looking at the version number of the .dll /
..exe

If I find it, I'll post a link here.

mike

"Jeroen Smits" <sm***@bc-br.com> wrote in message
news:u8*************@TK2MSFTNGP10.phx.gbl...
Not as far as I know. I had to solve it using the following elaborate
technic:

create a small program that reads the date and time using DateTime.Now and
serializes it into a small file. This program is exucute just before the
compilation of my main program. The generated serialized file is then
included in the application as an embedded resouce. Then in the program I
read this resource and deserialize to get the compilation date and time
back...

It's a lot of work, but ik works.
Hope this helps.

"Michael A. Covington" <Mi*****@CovingtonInnovations.com> wrote in message
news:OK*************@TK2MSFTNGP09.phx.gbl...
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!


Nov 15 '05 #5

P: n/a
Try creating a FileInfo object by specifying the filepath of the dll.
Then you can view the last modified date.

Greetz,
-- Rob.

Michael Mayer wrote:
I saw somebody create a VS addin that sets the last two parts of the
assembly version to the date and time right before a build. I can't
find it now, but that would be another way (since you can pull up the
assembly version pretty easily in code). Plus it's kindof handy if
you need to know when you made a build just by looking at the version
number of the .dll / .exe

If I find it, I'll post a link here.

mike

"Jeroen Smits" <sm***@bc-br.com> wrote in message
news:u8*************@TK2MSFTNGP10.phx.gbl...
Not as far as I know. I had to solve it using the following elaborate
technic:

create a small program that reads the date and time using
DateTime.Now and serializes it into a small file. This program is
exucute just before the compilation of my main program. The
generated serialized file is then included in the application as an
embedded resouce. Then in the program I read this resource and
deserialize to get the compilation date and time back...

It's a lot of work, but ik works.
Hope this helps.

"Michael A. Covington" <Mi*****@CovingtonInnovations.com> wrote in
message news:OK*************@TK2MSFTNGP09.phx.gbl...
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!

Nov 15 '05 #6

P: n/a
Try creating a FileInfo object by specifying the filepath of the dll.
Then you can view the last modified date.

Greetz,
-- Rob.

Michael Mayer wrote:
I saw somebody create a VS addin that sets the last two parts of the
assembly version to the date and time right before a build. I can't
find it now, but that would be another way (since you can pull up the
assembly version pretty easily in code). Plus it's kindof handy if
you need to know when you made a build just by looking at the version
number of the .dll / .exe

If I find it, I'll post a link here.

mike

"Jeroen Smits" <sm***@bc-br.com> wrote in message
news:u8*************@TK2MSFTNGP10.phx.gbl...
Not as far as I know. I had to solve it using the following elaborate
technic:

create a small program that reads the date and time using
DateTime.Now and serializes it into a small file. This program is
exucute just before the compilation of my main program. The
generated serialized file is then included in the application as an
embedded resouce. Then in the program I read this resource and
deserialize to get the compilation date and time back...

It's a lot of work, but ik works.
Hope this helps.

"Michael A. Covington" <Mi*****@CovingtonInnovations.com> wrote in
message news:OK*************@TK2MSFTNGP09.phx.gbl...
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!

Nov 15 '05 #7

P: n/a
[assembly:AssemblyFileVersion("1.0.*")]

This will change into an attribute where the 3rd part is the number of days
since Jan 1, 2000, and the 4th part is the number of seconds since midnight
(local time) divided by 2. This attribute can be accessed from the Assembly
object, or as the FileVersion looking at the Win32 file version resource.

--
--Grant
This posting is provided "AS IS" with no warranties, and confers no rights.
"Michael Mayer" <mi**@mag37.com> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
I saw somebody create a VS addin that sets the last two parts of the
assembly version to the date and time right before a build. I can't find it now, but that would be another way (since you can pull up the assembly
version pretty easily in code). Plus it's kindof handy if you need to know when you made a build just by looking at the version number of the .dll /
.exe

If I find it, I'll post a link here.

mike

"Jeroen Smits" <sm***@bc-br.com> wrote in message
news:u8*************@TK2MSFTNGP10.phx.gbl...
Not as far as I know. I had to solve it using the following elaborate
technic:

create a small program that reads the date and time using DateTime.Now and serializes it into a small file. This program is exucute just before the
compilation of my main program. The generated serialized file is then
included in the application as an embedded resouce. Then in the program I read this resource and deserialize to get the compilation date and time
back...

It's a lot of work, but ik works.
Hope this helps.

"Michael A. Covington" <Mi*****@CovingtonInnovations.com> wrote in message news:OK*************@TK2MSFTNGP09.phx.gbl...
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!



Nov 15 '05 #8

P: n/a

"Michael A. Covington" <Mi*****@CovingtonInnovations.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

"Grant Richins [MS]" <gr*****@online.microsoft.com> wrote in message
news:uf**************@TK2MSFTNGP09.phx.gbl...
[assembly:AssemblyFileVersion("1.0.*")]

This will change into an attribute where the 3rd part is the number of

days
since Jan 1, 2000, and the 4th part is the number of seconds since

midnight
(local time) divided by 2. This attribute can be accessed from the

Assembly
object, or as the FileVersion looking at the Win32 file version

resource.

And for posterity, here is some working code. Thanks again!

private DateTime DateCompiled()

// Assumes that in AssemblyInfo.cs,
// the version is specified as 1.0.* or the like,
// with only 2 numbers specified;
// the next two are generated from the date.
// This routine decodes them.

{

System.Version v =
System.Reflection.Assembly.GetExecutingAssembly(). GetName().Version;

// v.Build is days since Jan. 1, 2000
// v.Revision*2 is seconds since local midnight
// (NEVER daylight saving time)

DateTime t = new DateTime(
v.Build * TimeSpan.TicksPerDay +
v.Revision * TimeSpan.TicksPerSecond * 2
).AddYears(1999);

return t;
}

Nov 15 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.