But sometimes, it feels like MSBuild wasn't really deigned for this type of activity. We'd previously had issues with locked files which we'd managed to resolve, but even with no over-lapping project compilations, we were still hitting a locked file during copy operations from time to time.
We would see an MSB3021 sporadically, in different branches, on different computers. Ther was no pattern of behaviour would could discern.
MSBuild will complain that it couldn't copy a file because it was locked.
It is normally, an assembly being copied into BIN
E.g. "The process cannot access the file ______.___ because it is being used by another process. msbuild"
Also, the problem can manifest within Windows Explorer:
- The file can not be deleted
- You can not take ownership of the file
The only cure, appears to be rebooting the PC, then the file is gone.
Absolutely no idea, it seems to strike randomly, and without reason.
In our case, we made three modifications, based upon other peoples experiences.
1) Enabled the "Application Experience" service.
2) Allowed MSBuild to use Hard Links (aka. Symbolic Links)
The Hard Link effectively creates an alias to the original file, and doesn't attempt to copy it.
3) Allows MSBuild's copy task(s) to try again without failing on the first encounter.