If you have written an application, you often need the time stamp when the application was built. You can insert the time stamp manually but this is not very reliable because you might forget it. This article presents a command line tool which automates this process.
Background
In .NET, there is no macro or something similar to insert the current time stamp directly into the source code of an application. So I have written a small tool that does this job.
Using the Code
The command line tool "TimeStampGenerator.exe" is able to insert the current time stamp into a freely selectable C# source file. You can either create a new file or use an existing file for inserting the time stamp. If you create a new file, name it "Project.cs" and insert the following code:
namespace YourProjectName
{
public static class Project
{
public static DateTime AppCreationTimeStamp = new DateTime();
}
}
Here, a static
class Project
is created and in this class, there is a static
member AppCreationTimeStamp
for inserting the time stamp later when the build process is started. The name of the class is arbitrary but the time stamp member AppCreationTimeStamp
is a fixed name. Save this file as "Project.cs" in your project folder. Alternatively, you can use an existing file. In this case, insert the following code somewhere:
DateTime AppCreationTimeStamp = new DateTime();
This code must be taken exactly as it is. Do not add or remove space characters or line breaks, but you may add statements in front of the code or comments behind it.
In order to setup the time stamp generator, perform the following steps. Here, it is assumed that the source file for inserting the time stamp has the name "Project.cs" and that this file is already added to your project:
If you then build your application, the file "Project.cs" is changed and the current time stamp is inserted. In the output area of Visual Studio, there should be the message:
1> TimeStampGenerator 1.0: Time stamp was successfully inserted into the file "C:\...\Project.cs".
History
Version number | Date | Description |
1.0 | 2021-04-06 | Initial version |
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.