I have also being frustrated by this exact same problem for weeks. It would work maybe 2 out of every 10 attempts, and the rest of the time I would encounter “The Directory is not empty” error.
To troubleshoot I proceeded to stop every single windows service one by one to attempt to identify the problem, which I finally did. In my case it was not the AV software, it was a process called IDriveE which is part of an online backup solution called
iDrive.
As Emma Em pointed out above, I suspect this process is interfering with file system access in some way. As soon as I stopped this process, I can publish straight from Visual Studio without any more of these errors.
If you are having the same problem and come across this thread, I recommend that you inspect your system for any services or processes that might be affecting the file system, or doing some sort of a continuous scan on the drive. This is most likely the
culprit.