Close and reopen Visual Studio is the way to fix. It could mean that the executable VS is trying to build is currently running. Have you launched it by Control-clicking the Start button or double-clicking the .exe file in File Explorer? @adv12 I launched it normally.
The bin folder holds binary files, which are the actual executable code for your application or library. Each of these folders are further subdivided into Debug and Release folders, which simply correspond to the project's build configurations.
This is going to sound stupid, but I tried all these solutions, running VS2010 on Windows 7. None of them worked except the renaming and building, which was VERY tedious to say the least. Eventually, I tracked down the culprit, and I find it hard to believe. But I was using the following code in AssemblyInfo.cs...
[assembly: AssemblyVersion("2.0.*")]
This is pretty common, but for some reason, changing the version to 2.0.0.0 made things work again. I don't know if it's a Windows 7 specific thing (I've only been using it for 3-4 weeks), or if it's random, or what, but it fixed it for me. I'm guessing that VS was keeping a handle on each file it generated, so it would know how to increment things? I'm really not sure and have never seen this happen before. But if someone else out there is also pulling their hair out, give it a try.
Since I haven't gotten any more feedback on this issue, I thought I'd just share what ended up being my solution:
As suggested by Barry in a comment to the original post, manually renaming the '...bin\Debug[ProjectName].exe' to something else (e.g. '[ProjectName]1.exe') is one work-around (I'm however not allowed to delete the file myself, and I must say I find that a bit weird as one would believe the same lock preventing deletion would also prevent renaming...). It's not a good solution, but it's reasonable fast (at least after you've done it a couple of times, it almost becomes a routine), and at least way faster than restarting Visual Studio which is what I did in the beginning.
In case somebody wonders, I could also add that I only see this problem semi-randomly. It usually happens after I've done some changes in the design mode of a form (but not always). It usually doesn't happen if I only change business-logic code or non-visual related code (but sometimes it does...). Frustrating indeed, but at least I have a hack that works for me - let's just hope that my next project doesn't face this problem as well...
@Barry: if you would like to get credit for your comment, please feel free to post it as an answer and I'll make sure to accept it :)
I found one simple solution, just disable the Windows Indexing Services for the project folder and subfolders
I have the same problem (MSB3021) with WPF project in VS2008 (on Windows 7 x32). The problem appearing if i try to re-run application too quick after previous run. After a few minutes exe-file unlocked by itself and i can re-run application again. But such a long pause angers me. The only thing that really helped me was running VS as Administrator.
When I have come across this problem it is to do with the Fact that the project I am trying to build is set as the Startup project in the solution making the .exe in the obj folder locked ( it also appears in your task manager,) right click another project in your solution and choose set startup project. This will release the lock, remove it from task manager and should let you build.
I tried all the other suggestions in the answers here, none of which worked. Eventually I used Process Monitor to discover that my .exe that VS2010 was failing to build was locked by the System process (PID=4). Searching SO for situations involving this yielded this answer.
Summarised: if you have the Application Experience service disabled (as I did) then re-enable and start it. Two years of aggravation ended.
I also had a problem very similar to this and found the reason in my case was that I had made the bin\debug folder available as a shared folder under VMware and either VMware, Explorer under the VM guest, or maybe even an anti-virus program under the guest (though I don't think I had one installed) was holding a handle to the file(s).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With