Visual Studio 2010: unable to copy file while debugging

I have a problem over time (since I am using Visual Studio 2010, I think). When I try to start debugging in my web application, I accidentally get this error from VS.net environment:

Error 1 Failed to copy the file "obj \ Debug \ SolutionName.exe" to "bin \ Debug \ SolutionName.exe". The process cannot access the file 'bin \ Debug \ SolutionName.exe' because it is being used by another process.

The only way to get rid of this error is to restart Visual Studio (in order to receive an error message in the near future approximately twice a day).

After a short search on the Internet, I found out that you can add pre-builders, from here the MSDN link

All I found was to write something in the pre-build events and do some file processing ... well (this still doesn't work).

Question 1: Is there an easier way to solve this problem (and always!)
Question 2: What is the specific cause of this problem?

+6
source share
1 answer

This is due to shadow copying. You can disable it like this: web.config:

hostingEnvironment shadowCopyBinAssemblies="false" 

You can also use a workaround if the above settings do not work at all with the pre-build event:

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

You can completely disable the ShadowCopy service on Windows so that you do not have to set these values ​​for all solutions, but this will greatly disrupt the functionality, so I do not recommend it.

You can always use a custom script batch to trigger the postbuild event of the last project (in accordance with the build order), which will perform all copy operations (which I am using now).

+3
source

Source: https://habr.com/ru/post/885991/


All Articles