41

I keep getting:

warning MSB3026: Could not copy dlls errors.

I have several projects in the solution.

On build, I also get the error:

Error 47 Could not copy "myapp\bin\Debug*.dll" to "bin*.dll". Exceeded retry count of 10. Failed.

The application just stops responding in the middle of debugging, and I have to close Visual Studio every time. Which was annoying, but now it's getting frustrating as well.

We are eight team members, and all of us are getting the same error. We can't rebuild the solution, and the application is running very slow.

One of things we are using in the project is SignalR.

These are the things I have tried so far. They didn't help me, but they might help the reader:

  1. I have tried solutions described in Visual Studio debugging/loading very slow, but that didn't work.

  2. I have also tried unchecking Enable the Visual Studio hosting process in each project properties and that didn't fix the issue either.

  3. Solutions are described in http://www.richard-banks.org/2008/04/how-to-fix-problems-with-locked-files.html and http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/40ed753e-47af-4638-8a72-1d607102a05c/

  4. Pre-build scripts on the projects: if exist "$(TargetPath).locked" del "$(TargetPath).locked" if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"

  5. The bin folders are not under source control.

  6. Sometimes killing the Microsoft.VisualStudio.Web.Host.exe process releases the lock on the files, but this does not always work.

  7. I am running Visual Studio in administrator mode.

  8. I have full access (permissions read/write) on the source code folders.

Community
  • 1
  • 1
Oxon
  • 4,901
  • 8
  • 40
  • 54
  • is this a build or deploy error? – Dave Alperovich Mar 28 '13 at 18:44
  • when i try to rebuild or clean the solution i get this error. the application is also running very slow. i always have to restart visual studio or kill the web.host.exe process before rebuilding the solution. – Oxon Mar 28 '13 at 18:57
  • by the way i have also tried solutions described here: http://www.richard-banks.org/2008/04/how-to-fix-problems-with-locked-files.html and http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/40ed753e-47af-4638-8a72-1d607102a05c/ – Oxon Mar 28 '13 at 18:58
  • are you using any build definitions? – Dave Alperovich Mar 28 '13 at 19:00
  • are you using a shared library between multiple projects? – Dave Alperovich Mar 28 '13 at 19:00
  • yes i am using a couple of shared libraries (like data transfer objects and utilities projects). – Oxon Mar 28 '13 at 19:02
  • and no build definitions. – Oxon Mar 28 '13 at 19:09
  • have you tried cleaning and rebuilding your data layer? – Dave Alperovich Mar 28 '13 at 19:23
  • yes i have tried that. killing the process or closing/reopening the visual studio lets me do a clean but when i debug the app and then stop the debugging after that i cant clean the solution. and the rebuild also fails to delete the dlls. – Oxon Mar 28 '13 at 21:20
  • sounds like a locking issue. Still missing something, but not sure what... – Dave Alperovich Mar 28 '13 at 21:46
  • We are eight in the team and all of us are getting the same issue. Exactly the same issue. I have made sure that the bin folders are not under source control. I posted this question after nearly a month of trying everything I could find on the internet. Now its getting to a stage where it is really bothering me very much. – Oxon Mar 29 '13 at 11:13
  • I have also tried the following prebuild script on each project. `if exist "$(TargetPath).locked" del "$(TargetPath).locked" if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"` – Oxon Mar 29 '13 at 11:23
  • I have the same issue with a very simple project, few source files, and only "System" as a reference. No databases, no IIS, no funky stuff. Using Visual Studio 2010 on Windows 7 64-bit. If I launch my program and let it run until the end, then I can modify it and rebuild just fine. But if I break into it while it is running, and terminate it, then the next attempt to build will fail with MSB3026. It is driving me nuts. I am seriously considering launching a 32-bit Windows XP virtual machine to do my development in, because this situation is just unbearable. – Mike Nakis May 27 '13 at 21:44
  • 1
    Yep, this has been driving me nuts as well. Did VStudio 2013 become worse on this problem? I've wondered if being able to alter the code while running setting makes this problem worse? – Nicholas Petersen Feb 06 '14 at 00:05
  • I have installed vs 2013 but because of tight deadlines I haven't been able to try my hands on it. Would be great if the issue is fixed in vs 2013. I never alter the code while debugging. I have the option turned off anyway. – Oxon Feb 06 '14 at 14:12

13 Answers13

12

This is generally a permissions issue with your bin directory. Navigate to it in Windows Explorer and make sure readonly is off. If you get an error changing the read status of the directory, make sure you're running on an administrator-level account or elevate accordingly. Once write permissions are re-enabled, your build should work fine.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • 3
    thanks for the reply. that was the first thing i checked. the bin folder is readonly. if i uncheck and save it and open the properties again it goes back to readonly. there must be something that is setting it to readonly. – Oxon Mar 28 '13 at 19:11
  • If removing readonly isn't sticking, you may not have sufficient privileges to change it, or IIS Express may have gone off the rails. Again, make sure you are an administrator. You might want to open Windows Explorer temporarily as an admin (right-click, run as administrator) as well to get around any UAC weirdness. If that's not working, close Visual Studio completely and make sure that the devenv.exe process has been terminated. Then try changing it again and reopen Visual Studio afterwards. – Chris Pratt Mar 28 '13 at 19:25
  • 1
    Thanks Chris. I tried it this morning but the read-only attribute comes back as soon as I click OK on the properties popup. Visual Studio is closed. IIS Express is not running. The site is not using regular IIS. Microsoft.VisualStudio.Web.Host.exe is also not running. It must be something else then. I also killed all the TFS processes and still no luck. However, saying that, bin folder is read only but I can now delete all the files in the bin folder. – Oxon Mar 29 '13 at 11:21
  • 1
    Well, deleting everything in the bin folder should be as good as anything else. If the file isn't there, Visual Studio should have no problems writing it. Are you still having issues? – Chris Pratt Mar 30 '13 at 19:44
  • The thing is that closing visual studio every half an hour and deleting the files manually and reloading is not working very well for me. For example, right now, the application just stopped responding and I know if I close visual studio and delete the files in the bin folder then everything will be fine until the application wont build or will stop responding during the debug again. – Oxon Apr 02 '13 at 09:42
  • The bin folder is not read-only. The read-only checkbox is simply grayed, meaning that Windows does not know, or cannot be bothered to actually find out, whether the folder is in fact read-only. And actually it is not. The grayed read-only checkbox can be found in all folders in all windows installations, and it is just one of those ways that windows is broken and we have to live with it. It has nothing to do with the problem at hand. – Mike Nakis May 27 '13 at 21:40
  • It was indeed a permissions issue. Thanks for the answer. – JunaidKirkire Jan 07 '14 at 06:05
8

Clean Solution, then Rebuild Solution fixed this issue for me.
The first time I tried to perform a Clean, I got an access violation error.
To remedy that, I exited VS, manually deleted the bin folder, and opened it back up. Then I could perform the Clean.

This had nothing to do with permissions or access level.
Ensuring the output directory was not read-only and running VS as Admin did not help.

Please refer to Visual Studio “Could not copy” … during build.

Community
  • 1
  • 1
Scott Solmer
  • 3,871
  • 6
  • 44
  • 72
3

I ran into this issue as well, seems like a known bug in VS that randomly gets people from time to time in 2010, 2012 and 2013, I tried many of the suggestions here, as well as few found on other sites, none worked. What helped me was going into the debug properties for the project and clearing "Enable Visual Studio Hosting process", rebuild all and no more error.

Hopefully this will work for you, but that said, as it is a known reported bug in VS itself, we might all be fixing the symptoms and luckily doing something to clear the file lock and the real problem remains in VS.

Dano
  • 112
  • 7
3

Same issue for me. Solution was that I had my debugger still running the program in the background.

Ryan Young
  • 60
  • 7
2

I had this issue several days ago and tried many approaches but the solution that worked for me was stopping a windows service that was used by some class libraries from the project.

iusmar
  • 339
  • 1
  • 6
  • 15
2

Open cmd as admin. View tasklist with

=> tasklisk

Note the pid of the project .exe file. Run taskkill to kill the process

=> taskkill/F /IM pid

Restart visual studio, clean and rebuild project. That should get the job done.

1

I had the same issue. It seems that the dlls visual studio trying to copy is corrupt or something like that. I tried to copy the particular dlls to my desktop but it failed with error message. So I replaced the entire dlls with the fresh ones, which solved my problem. Hope that helps.

Redone
  • 1,253
  • 5
  • 18
  • 37
1

This worked for me:

  1. Close VS
  2. Delete bin and obj folders.
  3. If the project is located in any cloud-service-synced folder like OneDrive, move it to a local, regular folder.
  4. Delete .suo file inside solution folder
  5. Open VS again and rebuild.

Some similar issues deal with the dlls being locked so they cannot be copied, in which case, help can be found here and here!

0

This issue had been plaguing my development for sometime. Regardless of disabling the Read Only security permission and modifying access rights of the affect dlls.

I resolved the issue by ensuring the Security Permissions on the parent folder of solution allowed the computer's administrator read and write access and then ran Visual Studio in Administrator mode.

Jonathan Robbins
  • 2,027
  • 1
  • 16
  • 30
  • Thanks @jRobbins. I have full access to the source code folders and I am running visual studio in administrator mode. – Oxon Sep 27 '13 at 10:02
0

I had two projects

  • Source/Repos/Project1
  • Source/Repos/Project2

Project 1 had added Project 2 as an existing project (Two non-adjacent folders) The error message happened.

But when I moved Project2 (as a folder) into Project 1, then the error message left.

New Structure was:

  • Source/Repos/Project1
  • Source/Repos/Project1/Project2

Once I add The Project2 as an 'existing project' into Project 1 everything worked.

JWP
  • 6,672
  • 3
  • 50
  • 74
0

Check your project's folder path length.

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 19 '22 at 18:33
0

I had a unit test that remained hung after the test had "ended" in VS2022. I even closed VS2022 and the testhost.exe remained running.

The big clue is the first error of this type will include testhost.exe' is denied. and testhost.dll' is denied. because those are the programs generated for running a unit test.

I had to use End task in Task Manager in order to stop the hung test host. Then I was able to clean and rebuild.

HackSlash
  • 4,944
  • 2
  • 18
  • 44
-1

I had the same issue.Clear the browser history and build the project. which solved my problem. Hope that helps.

Vinoth
  • 1