11

In one cpp-file I use the __DATE__ macro to get the compile-date.

It gives me the date of the last compile of that file. But as the file is not changed very often, the date is old in most cases, sometimes several months.

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

Is there an setting to force VS2010 to rebuild that single cpp-file on every compile of the project? Regardless of changes in the file?

The only way I found until now is to modify the file or delete the created obj-file by an script before the build, I would prefer an solution inside VS if that is possible.

3 Answers 3

13

You could probably add a Pre-Build Step that touch (see this thread) the file?

To add a Pre-Build Step, open your Project Properties, then Configuration Properties > Build Events > Pre-Build Event then add the command line you want to have executed in Command Line.

Following the suggestion from Amitd, apparently you can also touch the file using PowerShell, see this for explanations.

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

del $(TargetDir)sourcefile.obj

Quoted 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.
Sign up to request clarification or add additional context in comments.

11 Comments

This would probably be a bit more complicated as, depending on your configuration, the .obj could be output at different places
There is no touch on windows, but your answer and google led me to the fact that "copy /b Source+,," has the same effect in windows, so that should work.
I prefer deleting the object file, as it allows the source file to remain read-only if you're using source control. The object file location may indeed depend on the configuration, but the macros make that simple to handle, e.g., del $(TargetDir)datefile.obj.
@MakGucky: 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.
$(IntDir) is probably preferable to $(TargetDir). Also, for some Studio versions the pre-build step will not be invoked if the project's dependencies do not require recompilation, so make it a post-build step instead.
|
1

You can add the following pre-build step, were you simply touch the date stamp of the file. The +,, is a special flag to the copy command, telling it to update the timestamp of the file:

copy file.cpp +,,

Comments

1

As suggested by Adrian McCarthy, you can simply delete the object file every time you build the project.

Therefore, create a pre-build event invoking the del command. According to Microsoft, you can use the $(IntDir) macro to refer to the directory wher the object file is stored (you should not use the $(TargetDir) macro).

I had issues with the return code of the command (error MSB3073), therefore I changed the command to always exit with 0.

del $(IntDir)datefile.obj & exit 0

Create this build event in the project configuration, under Configuration Properties / Build Events.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.