When I try to build my solution I often get this error:
Unable to copy file "obj\Debug\MyProjectXXX.dll" to "bin\Debug\MyProjectXXX.dll". The process cannot access the file 'bin\Debug\MyProjectXXX.dll' because it is being used by another process.
The project it's trying to build is a class library referenced by a couple of other projects in the solution.
The solution builds fine the first one or two times after opening Visual Studio, but after that the only way I can get it to build is to restart Visual Studio.
Any ideas what's wrong
Thanks

Unable to copy file during build
bklare
I'll be totally honest: I'm not exactly sure. I'm just passing on something that was passed on to me. My best guess is that the second line renames the -- potentially locked -- Target file, adding a .locked extension, so that the new Target file can be created. The first line just removes the existing .locked copy of the file which was created the last time the pre-build event was run.
It works, though, and that's the main thing.
Dario Galvani
PS. All references were done using project references (not file browse) and copylocal = true.
Kevin Stephens
When you created a reference to the project, did you do a project reference (via Add Reference -> Project tab) or a file reference (via Add Reference -> Browse tab)
Can you check that Copy Local is set to true:
Repeat this for each project that has a reference to the assembly.
Regards
David
syhzaidi
1. Clean the solution in Debug configuration
2. Change the configuration to Realease and clean the solution again
3. Start searching dll.* under the solution folder
4. You will see only the dll that is making you problems, why, because Clean deletes all project reference dll-s but not the file referenced
5. Delete those dll from search window
6. Build the solution
7. Fix the failed project that can't find file reference. Remove missing reference and add it as a project reference.
I hope this will help you.
Awaneesh
I'm not sure why this happens, but try adding these two lines to the "Pre-build event command line" in the MyProjectXXX properties (the line break before "move" has been added by the forum):
if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"
WorkflowDeveloper
Thanx a lot! You rule!
This was happening to me also, on a Visual Studio Add-in project, and your
solution solved it!
Every time I built and started the add-in, it would work, but if I wanted to
rebuild the project again and test it -- the dll would have been locked
and I would have to restart VS :-/
Thanx again!
kcchesnut
boban.s's instructions led me to find some designers that I had open in the editor.. specifically settings and resources designers.. closing them before build and run solved this problem for me.
--kg
GoDaddy
http://support.microsoft.com/default.aspx/kb/918007
I was expecting this error not appear in Visual Studio 2005.
Trilobyte
Hi there,
I just fix the same problem, but it is a long story, so hope u donot get bored.
My solution have about 10 projects, the core project use all the others. After some operation to SVN, I cannot build my core project but all the other are ok.
I use task manager find that once i load the solution, the core project's xxx.vshost.exe is running. and it restart after manually kill the task. then i look into my project, some usercontrols and forms cannot be open with designer, so here are the operations i fix this first. u may have one or all of them :)
1. In a usercontrol class's .resx file , i find a automatically generated XML code for one of the properties i defined in .cs file. it is designed for get info at runtime. however, the IDE properties try to read it at design time, so it fail to load the usercontrol.
i delete the associated xml code from .resx, and it works well now.
2. similarly, in the On_paint funtion of my usercontrol, i use a runtime class reference. so at the design time, when IDE load and try to show the usercontrol, and fail.
so i put a try{} cath{} to go around this, and it works well now.
after fix this two problems. the xxx.vshost.exe stop running. then my solution recovered from the error of
"Unable to copy file ..... "
I think the error is caused by the running xxx.host.exe, it occupies the .dll files so they cannot be replaced at the building time.
Hope this can help