Force MS VS2010 to rebuild one cpp file per build

In one cpp file, I use the __DATE__ macro to get the compilation date.

It gives me the last compilation date of this file . But since the file does not change very often, the date in most cases is old, sometimes several months.

What I really want is the date of the last build of the project .

Is there a parameter to force VS2010 to rebuild this single cpp file on every project compiler? Regardless of the changes to the file?

The only way I've found so far is to modify the file or delete the created obj file using a script before building, I would prefer a solution inside VS, if possible.

+8
c ++ visual-studio-2010
source share
2 answers

Perhaps you could add a Pre-Build Step , which is a touch (see this thread ) file?

To add a Pre-Build Step , open Project Properties , then Configuration Properties > Build Events > Pre-Build Event , then add the command line that you want to run on the Command Line .

Following Amitd's suggestion, you can also touch use the file using PowerShell, see this one for explanations.

As suggested by Adrian McCarthy in the comments below, deleting the .obj file would be preferable in the context of using the control source, and you want to keep the .cpp read-only . Using the "macros" exposed by Visual Studio, removing them can be simplified:

 del $(TargetDir)sourcefile.obj 

Quote from Cheers and hth. - Alf as another way to achieve this

 nmake (bundled with Visual Studio and the SDK) option /t does a touch, it was once the conventional way to do this for Windows programmers. 
+12
source share

You can add the next pre-build step, just tap the file date stamp. +,, is a special flag of the copy command, telling it to update the file’s timestamp:

 copy file.cpp +,, 
0
source share

All Articles