For simplicity, I have a project of which classes/files can be divided into two groups B and C.
C usually depends on (#include) some B.
Let's say C1,C2,... and C5 depend on B1, nothing special here:-
B1.h
class B1{/** some code */}; 
B1.cpp
#include "B1.h"
/** some code  */
C1.h
class C1{/** some code  */};
C1.cpp
#include "C1.h"
#include "B1.h"
/** some code  */
C2.h
class C2{/** some code  */};
C2.cpp
#include "C2.h"
#include "B1.h"
/** some code  */
Problem
When I modify B1.h and press F5, both C1.cpp and C2.cpp should be recompiled.
But in my case, it is not - VS recompiled only C1.cpp.     
I have to rebuild the whole project to indirectly force C2.cpp to be recompiled, otherwise this error will occur:-
a copy of B1.h was found in d:...\B1.h, but the current source code is different from the version built into d:...\B1.h.
Note: Two locations d:\...\B1.h are exactly the same.
After months of coding, this issue just happened to me yesterday.
The issue happens only for this certain file (B1.h), after an exhaustive bug hunting.
Other Bi are OK.     
What I have tried
(similar to answers for this question)
- Delete everything in bin folder (both debug & release) - the #Xfolder (see below)
- Clean project & rebuild (It is just a one-time cure.)
- Refactor (automatic rename) B1to something else (also the file name)
- Remove the file, create a new file B1.h, then copy source code from oldB1.h.
- Restart my computer several times
- Remove everything in Visual Studio's Temp folder  (%Temp%)
- Remove all .suo,.user,.ncb,.sbr,.log,.sdf,.pdbrelated to my project
- Make sure C2.cpp'sdate modifiedtime and system time correct.
- (Edit) Make sure stdafx.hdoesn't include any files that is a part of my project, e.g.B,C, and others that includeBorC(in)directly.
- (Edit) Make sure stdafx.his not#include-ed by any files, except from project setting.
 Thank Ari0nhh, user975989 and TripeHound.
- (Edit) Make sure, when full rebuild, C2.cppreally includesB1.h(look atshow include's console).
- (Edit) Repairing VS2015 does not help.
- (Edit) Uninstalling most VS2015 extensions does not help.
Clue 1
If I modify C2.cpp (e.g. adding a space character), then save and build, C2.cpp will be linked to B1.h.      
Now, if I edit B1.h and press F5, C2.cpp will now be recompiled automatically (correct).
It is not a cure because I also have a lot of other than C2 that want to link with B1.h.
... and it is very suspicious
... after I changed some project setting (not sure which), C2.cpp is not linked anymore.
Clue 2
Remove / recreate a new file B1.h
This solution cures the problem but the effect will vanish if I restart computer. 
Question
- How to fix the project to make the automatic-recompilation process correct again?
 More specifically, I am searching for some kind of "ultimate clean / repair this project" button.
- (secondary question) What is the cause of the issue?
It is hard to pinpoint the cause, so partial answers or unsure guess are welcomed.
Some progress
After a day, it finally recompiled C2.cpp correctly - even after a computer restart.    
I am still not sure which of my action that fixed it.
However, here is my guess, just in case it may be useful for someone.
My project file structure is as followed:-
F/
F/Debug/     <--#X contains .exe,.exp,.ilk,.lib,.pdb; one file per type
F/Release/
F/F/         <-- contains all my .cpp,.h; 
F/F/Debug/   <--#Y contains many .obj of my own code, .pch, .log, .tlog
F/F/Release/
I had deleted everything in #X, but not #Y.
Deleting all .obj in #Y might be the action that solves the issue.
I will have to test it more to see how much this approach is reliable ...
Note that all of the above questions are still unanswered.
 
    