Visual Studio “Could not copy” … during build

2019-01-03 20:53发布

I keep getting this error during the build of my VS2012 C# project

Error   41  Could not copy "obj\Debug\WeinGartner.WeinCad.exe" to
 "bin\Debug\WeinGartner.WeinCad.exe". 
 Exceeded retry count of 10. Failed.    


Error   42  Unable to copy file "obj\Debug\WeinGartner.WeinCad.exe" to
"bin\Debug\WeinGartner.WeinCad.exe". The process cannot access the file
'bin\Debug\WeinGartner.WeinCad.exe' because it is being used by another 
process.    

Now I've figured out that killing the process

Weingartner.WeinCad.vhost.exe

works (sometimes ) but this is getting on my nerves. Any way to stop this happening at all?

My debugger settings are

enter image description here enter image description here

30条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-01-03 21:28

I think I solved it removing the check mark to Break all processes when one process breaks in Debug options (op's first screenshot->second option).
It's been building/running well for a while since I unchecked it.
I'm using MySql NET Connector and DevExpress controls in my project. May be one of them was not disposing connections, bindings, etc. well because of this flag beeing activated.

EDITED: definitely it works! No more 'Unable to copy file' and no more Form designer errors.

查看更多
Fickle 薄情
3楼-- · 2019-01-03 21:31

I didn't realize I still had my debugger attached and was trying to build in the same Visual Studio instance. Once I stopped the debugger I was able to build.

查看更多
Ridiculous、
4楼-- · 2019-01-03 21:32

I have solved it by killing IISExpress in task manager

查看更多
男人必须洒脱
5楼-- · 2019-01-03 21:33

My 10 cents contribution.

I still have this problem occasionally on VS 2015 Update 2.

I found that switching compilation target solves the problem.

Try this: if you are in DEBUG switch to RELEASE and build, then back to DEBUG. The problem is gone.

Stefano

查看更多
祖国的老花朵
6楼-- · 2019-01-03 21:34

In Visual Studio Premium 2013 (Update 3), I solved this with a pre-build one-liner:

(if exist "$(TargetDir)*old.pdb" del "$(TargetDir)*old.pdb") & (if exist "$(TargetDir)*.pdb" ren "$(TargetDir)*.pdb" *.old.pdb)

This gracefully deletes any old PDB files (if it can), then renames anything that's left with a .old.pdb extension. A nice side effect is that if the old PDB is still locked, it just adds another .old piece to the filename, and they all get cleaned up next time you restart Visual Studio and do a build.

For example, build/debug session 1 leaves MyProject.pdb locked.
The next time you build:
MyProject.pdb --> MyProject.old.pdb

Then, build/debug session 2 is started, and both MyProject.pdb and MyProject.old.pdb are still locked:
MyProject.old.pdb --> MyProject.old.old.pdb
MyProject.pdb --> MyProject.old.pdb

Finally, restarting Visual Studio and doing a fresh build will get rid of both of these, and continue the process as usual.

查看更多
Emotional °昔
7楼-- · 2019-01-03 21:34

This question was the first result when looking for the following error:

Could not copy the file "..." because it was not found.

when building in Visual Studio 2013 (Update 3).

Solution: Uninstalling the "Productivity Power Tools" in Visual Studio 2013.

https://connect.microsoft.com/VisualStudio/feedback/details/533411

查看更多
登录 后发表回答