Visual Studio 是否可以记住源文件的 MD5,以避免在时间戳更改但内容更改时重建它们?
大多数时候,我在同一个项目上进行几个不同的开发,为了在它们之间进行逻辑分离,我在项目上使用个人版本控制系统(即 化石 但这可能是太多细节了)。
这允许我将我的工作提交到不同的分支中,以便之后合并它们。同时,我维护一个主干分支,在其中由同事提交工作。
但是,当我从一个分支切换到另一个分支(例如为了执行某些合并操作)并返回到我原来的位置时,Visual Studio 将检测时间戳修改并重建尚未真正修改的文件。
有没有办法让 Visual Studio 在仅更改源文件内容的某些哈希值时认为源文件已更改?
由于答案似乎是“不”,这里是实现我想要的目标的另一种方式,为此我开始悬赏。请仍然阅读上面的内容。
您是否知道一种简单的方法来获取源文件的时间戳和 MD5 哈希值的快照,然后对于时间戳发生更改的每个文件,比较 MD5 和回滚时间戳修改(如果 MD5 未更改)?
谢谢您的回答。
Most of the time I am doing several distinct developments on the same project and, in order to have some logical separation between them, I use a personal version control system on a project (namely fossil but this is mabye too much detail).
This allows me to commit my work in different branches in order to merge them afterwards. Meanwhile I maintain a trunk branch in which I commit work by coworkers.
But when I switch from a branch to another one (in order to perform some merge action for instance) and go back to where I came from, Visual studio will detect timestamp modifications and rebuild files that have not really be modified.
Is there a way to ask Visual Studio to consider that a source file has changed when only some hash of its contents has changed?
As the answer seems to be “no” here is another way of achieving what I would like, for which I am starting a bounty. Still read the above please.
Do you know of a simple way to have a snapshot of the timestamps and MD5 hashes of my source files, and then, for every file of which the timestamp changed, compare MD5 and rollback timestamp modification if MD5 has not changed?
Thank you for your answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
恐怕这实际上是不可能的。
这里的问题是,这不仅仅是 VS 的问题,实际上是整个构建系统的问题,它与实际的 IDE 完全分开。
为了决定是否应该编译
.obj
,VS 会将其时间戳与源文件的时间戳进行比较。按照您的建议操作将要求.obj
文件包含文件的 MD5。这也适用于.exe
和.dll
文件。对于这样一个很少需要的功能来说,更改这些文件的二进制格式不太可能发生。编辑-我收回它,这在理论上可能是可能的。一种方法是编写 VS 插件。该插件会将 MD5 保存到输出目录中的某个文件中,并且在构建开始之前将更新相应文件的修改日期。
进一步思考,这可能使用预构建步骤来实现..?
I'm afraid this is not really possible.
The issue here is that this is not just a thing for VS but actually for the entire build system which is quite separate from the actual IDE.
In order to decide if and
.obj
should be compiled, VS compares its timestamp to that of the source file. Doing what you suggest will require the.obj
file to include the MD5 of the file. This also goes for.exe
and.dll
files. Changing the binary format of these files and unlikely to happen for such a rarely needed feature.Edit - I take it back, this is probably is possible in theory. One way to go is to write a VS plugin. The plugin would save the MD5s to some file in the output directory and the just before the build starts will update the modified dates of the appropriate files.
Thinking further, this might be possible using a pre-build step..?
一个简单的解决方法可能是编写一个脚本,该脚本查看 Visual Studio 不知道的文件,如果该文件已更改,则复制该文件以覆盖 Visual Studio 知道的文件。然后,Visual Studio 看到的文件将从源代码管理中排除,因此不应触及它的时间戳。
复制决策可能基于哈希值,但它也可以轻松地直接比较源文件和目标文件。
Visual Studio 绝对有能力在构建中包含代码生成器 - 这就是 Visual Studio 眼中的脚本。但我不知道细节 - 我让 cmake 为我管理这些事情。
A simple workaround may be to write a script which looks at a file that Visual Studio isn't aware of and, if it has changed, copies it to overwrite the file that Visual Studio is aware of. The file Visual Studio sees is then excluded from source control, so it's timestamps shouldn't get touched.
The copying decision might be based on a hash, but it could just as easily compare the source and destination files directly.
Visual Studio definitely has the ability to include code generators in the build - which is what this script would be, in Visual Studios eyes. I don't know the details though - I get cmake to manage these things for me.