Nailed you - Cannot copy assembly 'xxx' to file 'path\xxx.dll'. Access is denied.
Hey folks,
I’m sure that all of you encountered this message at least once in your life as a programmer.
Well, I’ve managed to understand and fix one aspect(\scenario) of the beast:
In my project, I have a directory named “References” which holds all my compiled (in Release mode of course) Dlls which are being used as “black box” component (i.e file reference). Because of all these files are in the VSS and I put them as “Solution Items”(easier deployment), they downloaded to my computer as “Read-only” files. So at the first time the solution builds, no problem, The web project can copy those Dlls (they are not exist in his bin directory), afterwards it’s working fine as well (later builds) because there are no changes to this Dlls so the VS.NET simply don’t copy them again (like “he” don’t compile the ClassLibrary if no changes were made, he’s a smart fellow you know).
BUT, in my scenario, I’ve updated one of those “black box” Dll and I tried to rebuild my solution. You can understand from the title that I got this annoying message that it can’t copy the Dll. After I’ve checked a little, I found out the problematic file in my webproject\bin directory is checked as read-only, So I’ve unchecked it, rebuild the solution and it worked faultlessly.
If found 2 solutions for this problem:
- Call attrib -r [path-to-web-project]\bin\*.dll on pre-build (Build Event) of any ClassLibrary project; I would’ve put it in my WebProject project but unfortunately it doesn’t support Build Events (why MS, why ?)
- Go to your “References” directory and manualy set all the files to *NOT* Read-only.