5

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.

3
  • What version of VS is this? What language are you using? Feb 9, 2012 at 23:13
  • @ConradFrix VS2008, C++. Feb 10, 2012 at 0:01
  • 6
    Those voting to close - programming tools are on topic on SO :)
    – user257111
    Feb 10, 2012 at 11:22

2 Answers 2

5

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.

1
  • I just did some of my own tests because I wanted to know if it kept the modified time per file or per build. It appears from my testing it only keeps the last build time, then compares that to a file's last modified time. Thus it will only recompile if the file's modified time advances past the last build time. Even if it advances but not enough, it won't recompile.
    – jgawrych
    Feb 12, 2018 at 19:46
2

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.

8
  • 1
    Isn't VS mostly Win32, aside from 2010's WPF user interface components?
    – p.campbell
    Feb 9, 2012 at 21:43
  • Right, was just thinking of the approach generally. And even this .NET class is likely (like others) just a Win32 wrapper. Applied notes to post update.
    – Meligy
    Feb 9, 2012 at 21:53
  • This answer illustrates itself why questions asking for speculation are not constructive... what's the point of guessing what VS uses to do this? Feb 9, 2012 at 21:54
  • 1
    But what happens if I change the files when VS is not active? Also as far as I know Windows caches frequently used files in memory and redirects all reads/write to this memory. The synchronization with hard disk is delayed to later time. Please correct me if I am wrong. Feb 9, 2012 at 21:55
  • @AndrewBarber I use Git for version control and often change branches. This causes some files to change timestamp, but not to change the actual content. I would like to understand how does Visual Studio handle this. From my experience it seems like it does it differently every time, which I don't think is what actually happens. Probably I just do not understand how it works. Feb 9, 2012 at 21:57

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.