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.
To rebuild your project with the Visual C++ 11.0 Windows XP toolset, enter this command: MSBuild provides various ways to customize your build process. These articles show how to add custom build steps, tools, and events to your MSBuild project:
you can msbuild have invoke devenv to compile a single file: devenv myproject.sln /Command "File.OpenFile myfile.cpp" /Command "Build.Compile" /Command "File.Exit" this does open the IDE window though, and will make it pretty hard to figure out if the compile actually succeeded or not.
MSBuild in VS2008 uses VCBuild to do the actual work, and VCBuild has no option I know of to build a single file. (with VS2010 this has changed, there you can actually invoke a compile of a single file using something like "/t:ClCompile "p:/SelectedFiles="main.cpp")
*/ An MSBuild project file is an XML file that contains a project root element ( <Project> ). In the example project you'll build, the <Project> element contains seven child elements: Three item group tags ( <ItemGroup>) that specify project configuration and platform, source file name, and header file name.
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.
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 +,,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With