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条回答
Evening l夕情丶
2楼-- · 2019-01-03 21:35

I was able to fix this issue (VS 2010) through supplying following pre build action;

if exist "$(TargetPath).locked" del "$(TargetPath).locked"

if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"
查看更多
We Are One
3楼-- · 2019-01-03 21:36

Make sure u close all instances wcfSvcHost and try again. It worked for me!

查看更多
走好不送
4楼-- · 2019-01-03 21:37

I faced the same problem on VS 2012 Version 11.0.60610.01 Update 3 on Windows 8

There were no designer windows open and the project was a simple console application.

The removal of the vshost process accessing the file does not work most of the time since the process isn't accessing the file.

The simplest workaround that works and takes the least amount of time is to remove the project from the solution, build another project in the solution and then add the original back.

It's an irritant and waste of time but it's the least expensive of all the other options that I know of.

Hope this helps...

查看更多
何必那么认真
5楼-- · 2019-01-03 21:37
  1. Open project properties [ menu > project > properties ]
  2. Choose "debug" tab
  3. Uncheck "Enable the visual studio hosting process"
  4. Start debugging [F5]
  5. You will receive security warning , just "ok". Lets application running
  6. Stop debugging.
  7. Check option "Enable the visual studio hosting process" , under debug tab,
  8. Now , try to start debugging , you will not see error again

[Work for me]

查看更多
我命由我不由天
6楼-- · 2019-01-03 21:37

If none of the answers works, try this simple check. Find for any MSbuild.exe running and holding your project EXE. Kill MSBuild.exe and you should be good to go.

查看更多
我命由我不由天
7楼-- · 2019-01-03 21:38

Follow the below steps

  1. Open Task Manager ( Ctrl + Alt + Delete )
  2. Under Performance tab select select <ProjectNameOfYours.exe>.
  3. Click on End Process.
  4. Now Build solution.

Above steps resolved error permanently :)

查看更多
登录 后发表回答