Finally, I found some spare time at home to test a concept I was thinking about in a while. Without much thought, I started Visual Studio, created a blank console C# project, giving it the name 'Test'. How imaginative of me! Then out of habit I hit F5 to build and run it. To my surprise Visual Studio complained it could not create the file 'Test.exe', because the access to the path was denied. Wait! It was just a blank console project with an empty 'Main' method in it. If I fail to compile that, then what?
I tried the obvious things first like clean rebuild etc. to no avail. Then I tried to restart Visual Studio, delete the 'bin' and 'obj' folders in my project manually and then rebuild. Same outcome. Then I tried to restart Windows, delete the 'bin' and 'obj' folders in my project manually and then rebuild. Same thing. Then I tried to disable my antivirus program temporarily, suspecting it was confusing my poor empty console program with some nasty virus. Nope, it was not the antivirus.
During my struggles, I found something new however. The 'bin' folder was locked when the project was open in Visual Studio, while closing the project unlocked it. Deleting the 'bin' folder and reopening the project caused the 'bin' folder to be recreated and locked back again. The culprit always was some child process in Visual Studio, namely 'VBCSCompiler.exe'. So, it was the C# compiler itself locking the 'bin' folder and then failing to write 'Test.exe' in there!
I spent the rest of my spare time Googling about the problem to no avail. Finally, I had to tend to other matters, so I deleted the useless project and left home.
When I returned home, I recreated the console project. This time everything compiled without problem. After toying with my testbed for a while, I noticed there was a typo in the project's name: it was called 'Tset', instead of 'Test'. I hate such small mistakes, so I renamed the project to 'Test'. To my surprise, the problem with the locked folder reappeared. I was starting to feel I was going crazy, when it finally occurred to me. Went to project properties, renamed the generated executable from 'Test' to 'Test1' and it compiled normally. Renaming the executable back to 'Test' prevented me to compile again. So, it seemed I was unable to compile, when I put the name 'Test'. I tried with different project types and the problem reproduced always. C++ projects seemed unaffected, so my guess was it had something to do with the C# compiler.
And now the moral of the story is: do not give stupid names to your projects, otherwise the compiler will bite you!