put build date in about box

2019-05-04 00:17发布

I have a C# WinForms app with an About box. I am putting the version number in the about box using:

FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)
    .FileVersion

This ends up giving me the Subversion revision number from which the executable was built.

I would also like to get the date of the build into the About box. I tried:

File.GetLastWriteTime(Assembly.GetEntryAssembly().Location)

But that gives me the write date of the executable, which only corresponds to the date when the app was installed (we are using ClickOnce) not built.

How can I get the build date?

7条回答
何必那么认真
2楼-- · 2019-05-04 00:51

In Visual Studio projects there is a file AssemblyInfo.cs, but you can use any other .cs file. Look at the attribute AssemblyVersion:

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number 
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.*")]

Now you can calculate the build date by using the Version.Build property. The value that Version.Build returns is the number of days since: 2000/1/1

查看更多
登录 后发表回答