How to Permanently Fix “Could not copy “C:\MyProject\MyDLL.dll” to “C:\MyProject\bin\Debug\MyDLL.dll”.
Recently I had an issue where when I would try to run and debug a webapp inside Visual Studio 2017, I would get an error where the .dlls couldn’t be copied out to the bin directory, which meant I couldn’t actually run the app at all! I would keep getting this error: [blockquote]”Could not copy “C:\MyProject\MyDLL.dll” to “C:\MyProject\bin\Debug\MyDLL.dll”[/blockquote] This error is usually caused by a lock on the target file, preventing it from being deleted. There was only one problem – I had restarted Visual Studio and it was still happening. I even restarted my computer, which fixed the problem once, but subsequent runs brought the error back. The Root Cause The actual root cause ended up that I actually had multiple projects set up as my startup project, but ONE of the projects wasn’t set up to debug, while the other was. When you set the configuration in Visual Studio for a project to run without debugging, it actually doesn’t give the app the hooks that Visual Studio needs in order to close the app once you select “Stop Debugging”. This causes you to have an orphaned process, particularly if the app is set up as a headless console app or a windows service, where you don’t see anything on your screen to give you an indication of what’s running that has a hold on the files in...Read More