强制MS VS2010在每个版本上重建一个cpp文件 [英] force MS VS2010 to rebuild one cpp-file on every build

查看:25
本文介绍了强制MS VS2010在每个版本上重建一个cpp文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个cpp文件中,我使用 __ DATE __ 宏来获取编译日期.

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.

是否存在一项强制VS2010在项目的每次编译时重建单个cpp文件的设置?不管文件有什么变化?

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?

到目前为止,我发现的唯一方法是在构建之前通过脚本修改文件或删除创建的obj文件,如果可能的话,我希望在VS内提供解决方案.

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.

推荐答案

您可能可以添加触摸预构建步骤(请参见

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

要添加预构建步骤,请打开 Project Properties ,然后打开 Configuration Properties>建立事件>Pre-Build Event ,然后在 Command Line 中添加要执行的命令行.

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.

按照Amitd的建议,显然您也可以使用PowerShell touch 该文件,请参见

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

如Adrian McCarthy在下面的注释中所建议的那样,在使用源代码管理并且您想要保留 .cpp .obj 文件是更可取的.> 只读.使用Visual Studio公开的宏",可以很容易地删除它们:

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

引自Cheers和hth.-Alf是实现这一目标的另一种方法

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.

这篇关于强制MS VS2010在每个版本上重建一个cpp文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆