Put the build date in the box

I have a C # WinForms application with an About window. I put the version number in the about field using:

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

It ends up giving me the version number of Subversion from which the executable was created.

I would also like to get the build date in the "About" field. I tried:

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

But this gives me the record date of the executable, which only matches the installation date (we use ClickOnce), not built .. p>

How can I get the build date ?

+4
source share
7 answers

If you use automatic version control, you can convert the last two bits of the version number to the build date: MSDN

+5
source

We use this very similar piece of code:

 DateTime buildDate = new FileInfo(Assembly.GetExecutingAssembly().Location).LastWriteTime; 

and I'm sure this will not change when installing with ClickOnce. If I am wrong, please correct me!

+2
source

You can change the version of the assembly to encode the date, but that would probably mean losing subversion revision information, which might be more useful.

This should work: write the current date / time to a .cs file as a pre-build task as follows:

 [assembly: AssemblyCreated(CreatedDate = new DateTime(...))] 

To do this, you can use the PowerShell script command file or the executable file.

Include the file in your project (compile action: compile) and include the user attribute:

 [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)] public sealed class AssemblyCreatedAttribute : Attribute { public DateTime CreatedDate { get; set; } } 

When you start the application, you can use reflection to get a custom attribute from the assembly to display on the about page.

+1
source

The only way I was able to do this in C / C ++ was for the post-build process to actually search for and replace a special line highlighted as a β€œstatic constant” in binary format.

In C #, there might be an easier way.

0
source

I do not think that a standard way to do this exists, but you can download something yourself. Create a custom assembly-level attribute, give it a cool name, such as "AssemblyDateAttribute". Let it take a string that you can parse in DateTime in the constructor, accessible through the property.

As part of the build process, create a new file with the attribute that applies to the build. (Make it look like AssemblyInfo.cs), and then include it in your input.

Then, in the about about field, find your assembly for instances of this attribute and display the date value in your field.

0
source

Visual Studio projects have an AssemblyInfo.cs file, but you can use any other .cs file. Look at the AssemblyVersion attribute:

 // 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 using the Version.Build property. The value returned by Version.Build is the number of days since: 2000/1/1

0
source
 Assembly.GetExecutingAssembly().GetName().Version.ToString(); 

From my own C # code .

-1
source

All Articles