include build time in exe file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I would like to include the build time in my application.
It's for my ? / About ... menu. It's annoying to change the label.Text
property for every release.

Is it possible to do so?

Thanks,
Sitar.
 
You may get it from executing assembly:

System.Reflection.Assembly.Get­ExecutingAssembly().GetName().­Version

Also make sure that AssemblyInfo.cs contains the following string:

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


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
Ouch, I meant you may get an assembly version instead of build time.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Sergey said:
You may get it from executing assembly:

System.Reflection.Assembly.Get­ExecutingAssembly().GetName().­Version

Also make sure that AssemblyInfo.cs contains the following string:

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


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com

Hi,

I would like to include the build time in my application.
It's for my ? / About ... menu. It's annoying to change the
label.Text property for every release.

Is it possible to do so?

Thanks,
Sitar.
 
Hi Sitar

This might help
System.IO.File.GetCreationTime(Assembly.GetExecutingAssembly().Location)
 
Though ... I was close. To get build date (without time) try this:

Version version =
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
DateTime dt = new DateTime(2000, 1, 1);
label.Text = dt.AddDays(version.Build).ToString();


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Sergey said:
Ouch, I meant you may get an assembly version instead of build time.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Sergey said:
You may get it from executing assembly:

System.Reflection.Assembly.Get­ExecutingAssembly().GetName().­Version

Also make sure that AssemblyInfo.cs contains the following string:

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


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com

Hi,

I would like to include the build time in my application.
It's for my ? / About ... menu. It's annoying to change the
label.Text property for every release.

Is it possible to do so?

Thanks,
Sitar.
 
I used that one already so developpers can trace the version.
But the client specifically wants the build date and having to change the
date manually is not "damn I forgot"-free once the release is shipped already
:)

Thanks,
Sitar
__
Sergey Bogdanov said:
Ouch, I meant you may get an assembly version instead of build time.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Sergey said:
You may get it from executing assembly:

System.Reflection.Assembly.Get­ExecutingAssembly().GetName().­Version

Also make sure that AssemblyInfo.cs contains the following string:

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


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com

Hi,

I would like to include the build time in my application.
It's for my ? / About ... menu. It's annoying to change the
label.Text property for every release.

Is it possible to do so?

Thanks,
Sitar.
 
Sitar said:
Hi,

I would like to include the build time in my application.
It's for my ? / About ... menu. It's annoying to change the label.Text
property for every release.

Is it possible to do so?

There is a "magic" way. The actual date/time information of the last build
can be extracted from the version#. If you set the assemly version to
[assembly: AssemblyVersion("1.0.*")], which I think is the default. See the
code snippet below:

private void VersionInfo_Click(object sender, System.EventArgs e)
{
// user selected "VersionInfo" item
FileVersionInfo myFileVersionInfo =
FileVersionInfo.GetVersionInfo(Application.ExecutablePath);
// Print the file name and version number.
string str = "Version " + myFileVersionInfo.Comments;
int nBuild = myFileVersionInfo.FileBuildPart;
int nPrivate = myFileVersionInfo.FilePrivatePart;
DateTime dt = new DateTime(2000,1,1);
dt = dt.AddDays(nBuild);
dt = dt.AddSeconds(nPrivate * 2);
str += " Built " + dt.ToShortDateString() + " @ " +
dt.ToShortTimeString();
this.ctlBuild.Text = str;
}
 
That solution won't work on the Compact Framework since it is lacking the
System.Diagnostics.FileVersionInfo class (although I wrote a subset of it
for the SDF) - www.opennetcf.org/sdf/

Peter

--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://blog.opennetcf.org/pfoot/

Dan Baker said:
Sitar said:
Hi,

I would like to include the build time in my application.
It's for my ? / About ... menu. It's annoying to change the label.Text
property for every release.

Is it possible to do so?

There is a "magic" way. The actual date/time information of the last
build can be extracted from the version#. If you set the assemly version
to [assembly: AssemblyVersion("1.0.*")], which I think is the default.
See the code snippet below:

private void VersionInfo_Click(object sender, System.EventArgs e)
{
// user selected "VersionInfo" item
FileVersionInfo myFileVersionInfo =
FileVersionInfo.GetVersionInfo(Application.ExecutablePath);
// Print the file name and version number.
string str = "Version " + myFileVersionInfo.Comments;
int nBuild = myFileVersionInfo.FileBuildPart;
int nPrivate = myFileVersionInfo.FilePrivatePart;
DateTime dt = new DateTime(2000,1,1);
dt = dt.AddDays(nBuild);
dt = dt.AddSeconds(nPrivate * 2);
str += " Built " + dt.ToShortDateString() + " @ " +
dt.ToShortTimeString();
this.ctlBuild.Text = str;
}
 
I used Sergey's code in one line:
this.lblInfoVersion.Text+="\r\nBuilt "+new DateTime(2000, 1,
1).AddDays(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Build).ToShortDateString();

It works both on Desktop and CF.

Cheers,
Sitar.
 
Because the build number is the number of days since January 1st 2000. If
memory serves me right the revision is the number of seconds since midnight
divided by two.

Cheers
Daniel
 
Back
Top