Reputation: 71
All was fine for a while. Then, all out of the blue, Visual Studio failed to build when I was about to launch the application. I got the warning "Unable to delete file '...bin\Debug[ProjectName].exe'. Access to the path '...bin\Debug[ProjectName].exe' is denied." and the error "Unable to copy file 'obj\x86\Debug[ProjectName].exe' to 'bin\Debug[ProjectName].exe'. The process cannot access the file 'bin\Debug[ProjectName].exe' because it is being used by another process." (I get both the warning and the error when running Rebuild, but only the error when running Build - don't think that is relevant?)
I understand perfectly fine what the warning and error message says: Visual Studio is obviously trying to overwrite the exe-file while it the same time has a lock on it for some reason. However, this doesn't help me find a solution to the problem... The only thing I've found working is to shut down Visual Studio and start it again. Building and launching then works, untill I make a change in some of the forms, then I have the same problem again and have to restart... Quite frustrating!
As I mentioned above, this seems to be a known problem, so there are lots of suggested solutions. I'll just list what I've already tried here, so people know what to skip:
Creating a new clean solution and just copy the files from the old solution. Adding the following to the following to the project's pre-build event:
if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if not exist "$(TargetPath).locked" if exist "$(TargetPath)" move "$(TargetPath)" "$(TargetPath).locked"
Adding the following to the project properties (.csproj file):
<GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies>
However, none of them worked for me, so you can probably see why I'm starting to get a bit frustrated. I don't know where else to look, so I hope somebody has something to give me! Is this a bug in VS, and if so is there a patch? Or has I done something wrong, do I have a circular reference or similar, and if so how could I find out?
Any suggestions are highly appreciated :)
Update: As mentioned in comment below, I've also checked using Process Explorer that it actually is Visual Studio that is locking the file.
Upvotes: 0
Views: 223
Reputation: 17784
It seems to me that you have run the file \debug\OEE.windows.exe
manually by double clicking the the exe from file system. And you are trying to build your project from visual studio. What visual studio will do during build is that it will create new file oee.windows.exe
but it is unable to do so because the file with same name already exists and being used by a process.
Upvotes: 1
Reputation: 28970
You must close your session in execution before open session of debug.
You can try to kill the vshost.exe process:
taskkill /F /IM ".....vshosts.exe"
Link : http://msdn.microsoft.com/en-us/library/ms185330(v=vs.100).aspx
Upvotes: 1
Reputation: 70314
Close the program "OEE.Windows.exe" - you are probably testing it and tried to do a rebuild without closing it first.
Upvotes: 1