MS Visual Studio 如何确定源文件已更改?

发布于 2025-01-03 18:51:00 字数 238 浏览 2 评论 0原文

它是否使用修改时间戳或/并且是否检查实际内容是否已更改(例如通过比较校验和)?

编辑:我需要知道这一点,因为我使用 Git 进行源代码控制并经常更改分支。看来有时即使我将分支更改回来并强制(例如从 developmaster 然后再回到 develop),VS 也会重建一半的源文件。我想知道为什么会发生这种情况,为什么有时会发生而其他时候不会发生。

Does it use modification timestamp or/and does it check whether the actual content has changed (e.g. by comparing the checksum)?

Edit: I need to know this since I use Git for source control and often change branches. It appears that sometimes even if I change the branch back and force (e.g. from develop to master and then back to develop), the VS rebuilds half of the sources files. I wonder why this happens and why does it happen sometimes and does not happen the other times.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

日裸衫吸 2025-01-10 18:51:00

由于 Visual Studio 是一个闭源项目,我敢打赌只有开发人员才能给出它到底如何工作的明确答案。然而,就我的目的而言,测试一些场景就足够了。

我已经使用一个小型解决方案和其中的几个文件(一个标头和两个源文件)对其进行了测试。测试结果得出以下结论。 Visual Studio 查找修改日期和时间。即使文件内容相同 - 它也会编译该文件以及包含该文件的任何其他文件。如果修改日期和时间相同,即使内容不同也不会重新编译。 Visual Studio 忽略创建和访问日期和时间。

Since Visual Studio is a closed-source project, I bet only developers would be able to give a definite answer on how exactly does it work. However, for my purposes it is enough to test some scenarios.

I have tested it with a small solution and a couple of files in it (one header and two source files). Test results bring to the following conclusion. Visual Studio looks for modification date and time. Even if the file content is the same - it compiles this file and also any other files that include it. If the modification date and time are the same - it won't recompile it even if the content is different. Visual Studio ignores creation and access dates and times.

不羁少年 2025-01-10 18:51:00

我猜它在项目目录和链接文件(如果有的话)上使用 FileSystemWatcher ,只是因为这是做这种事情的正确方法。

一些谷歌搜索发现有关此类的更多信息(或者自己查找):

当然,当源文件打开时,它是编辑时的内容以及任何用户更改(甚至未保存)都会加载到 RAM 中,但它不会将其与磁盘内容进行比较(这会太慢),它会在以下情况下侦听系统事件:系统告诉它文件已更改。

更新:

可能不是那个类itslf,而是它的Win32版本,您知道大多数与系统相关的.NET功能类只是Win32包装器。

从这个 StackOverflow 答案: FileSystemWatcher 如何在另一台计算机上工作目录?
我认为它包装了这个API(不确定): http://msdn.microsoft .com/en-us/library/aa365465.aspx

更新 2:

这是 Microsoft 监视文件更改的方法:
http://msdn.microsoft.com/en -us/library/chzww271(v=vs.80).aspx

更新 3

这是一个旧答案,上面提到过这是一个猜测,因为正如其他答案中提到的,Visual Studio 是闭源的。值得一提的是,接受的答案建议 Visual Studio 改为查找文件修改日期,这表明它没有使用在这个答案中猜测的方法,并且它是错误的

我希望读者不介意在这个答案中为合理化可能性而付出的努力(导致读者不适或投反对票)。仅出于存档原因保留它。

I'm guessing it uses FileSystemWatcher on the project directories and linked files (if any), just because it's the right way to do this kind of thing.

Some googling finds for more about this class (or just look it up yourself):

Of course when the source file is open, it's content by the time of editing, as wel as any user changes (even not saved) are loaded in the RAM, but it doesn't compare it to disk content (that'd be too slow), it listens to a system event when the system tells it the file changed.

Update:

Probably not that class itslf, but the Win32 version of it, you know most of the system related .NET functionality classes are just Win32 wrappers.

From this StackOverflow answer: How does FileSystemWatcher work on another computers directory?
I think it wraps this API (not sure): http://msdn.microsoft.com/en-us/library/aa365465.aspx

Update 2:

This is Microsoft's approach to monitor file changes:
http://msdn.microsoft.com/en-us/library/chzww271(v=vs.80).aspx

Update 3

This is an old answer, and it was mentioned above that it was a guess, as Visual Studio is closed source as mentioned in other answers. It's worth mentioning that the accepted answer suggests Visual Studio looks for file modification dates instead, which suggests it doesn't use the approach guessed in this very answer, and that it was wrong.

I hope the reader didn't mind the effort given to rationalize possibilities in this answer (causing reader discomfort or down votes). Keeping it for archival reason only.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文