When you distribute your program, library, or xll addin it is usefull to have a function that can tell you when your project was compiled. This way you can ensure that the new program, library, or xll addin is correctly installed on a user’s system. In this post I will describe how to set up such function in your Visual Studio C++ project.
-
Create
timestamp.hwith the following content:1 2 3#include <string> std::string TestTimeStamp(); -
Create
timestamp.cppwith the following content:1 2 3 4 5 6 7 8 9 10#include "timestamp.h" std::string TestTimeStamp() { std::string date(__DATE__); std::string time(__TIME__); std::string res; res = date + " | " + time; return res; } -
Add custom build step to make sure that
timestamp.cppis compiled every time.-
Right click on the project in the
Solution Explorerand selectProperties -
Make sure that
Configurationis set toAll Configurations -
Go to
Configuration Properties>Custom Build Step>Generaland fill out options as follows:- Command Line:
del $(ProjectDir)$(Configuration)\timestamp.obj - Description:
Refresh timestamp - Outputs:
fake.cpp - Execute Before:
PreBuildEvent
- Command Line:

-
-
Now every time you compile the project the timestamp string returned by
TestTimeStamp()function is updated.