Visual Studio 2008 locks dll in bin folder and doesn't let go of it

夙愿已清 提交于 2019-12-12 08:07:04

问题


I am working on a solution consisting of 8 .NET projects. Since I am practicing TDD, I have to re-compile my solution very often. Lately I have been getting the following error about every second time when trying to compile:

Error 2 Unable to copy file "obj\Debug\Zeiterfassung.Tests.dll" to "bin\Debug\Zeiterfassung.Tests.dll". The process cannot access the file 'bin\Debug\Zeiterfassung.Tests.dll' because it is being used by another process.

Zeiterfassung.Tests.dll is the dll generated by one of my projects (it's the unit testing project). It's always this dll that cannot be copied and causes the error. Everything else works fine 100% of the time.

In about 9/10 times I can "solve" the problem by recompiling my solution again. But when the problem is getting really bad, the project just won't compile successfully no matter how often I try and I have to restart the IDE.

I used microsoft's handle.exe to ascertain which process is locking the DLL and it is devenv.exe. I also tried deleting the DLL by hand and it really can't be deleted until I restart the IDE.

Last but not least, I tried adding <GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies> to my project as suggested in another forum, but this did not help.

Please help! This problem is really starting to drive me nuts.

Edit: I might also add that I made sure my unit tests are finished when this problem occurrs. Still, the dll remains locked. I am running my tests via the Resharper unit test explorer.


回答1:


I've faced the same problem before. Process Explorer is able to delete the handle.




回答2:


The most likely problem is a threading issue. You probably had an itinerant thread that is still executing, and it has the reference to the .DLL.




回答3:


This worked for me: 1) Create new folder outside of the Project (c:\Debug); 2) Right click your Project and select Properties; 3) Locate Build tab; 4) Navigate to Output section in the Build tab (last one in VS2010); 5) Click Browse button and select your new c:\Debug location as an output directory; 6) Save all changes; 7) Build (F6);




回答4:


Visual Studio has had one or another problem like this since Day 1. It would be nice to give you a set of simple solutions that always work, but frankly, sometimes, it has just "tripped over its own feet".

In that case, the simple solution is to exit and restart. Even closing the solution and reopening may not help.




回答5:


By "I tried adding true to my project as suggested in another forum" do you mean that you created a property named GenerateResourceNeverLockTypeAssemblies and set it to true as suggested at http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/6f76db9a-ea37-42b3-a016-571912c28032? If not try that out.

Sayed Ibrahim Hashimi

My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build




回答6:


Looks like the bug disappeared (fingers crossed...) after I moved my test project, checked out an earlier version of the project from the repository and replaced all code files with the newer versions.




回答7:


I had a similar problem. I don't know of a nice solution, but a hack that solves the problem is to add a pre-build event that kills vstest.executionengine.exe:

taskkill /F /IM vstest.executionengine.exe /FI "MEMUSAGE gt 1"
taskkill /F /IM vstest.executionengine.x86.exe /FI "MEMUSAGE gt 1"


来源:https://stackoverflow.com/questions/1161856/visual-studio-2008-locks-dll-in-bin-folder-and-doesnt-let-go-of-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!