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;
}