Graviton
Graviton

Reputation: 83244

Unable to Copy File "*\bin\debug\*.dll" to "bin\*.dll" in Visual Studio

I encountered this problem

Unable to Copy File "*\bin\debug\*.dll" to "bin\*.dll"

And when this happens, the compilation will fail because of the above error.

Edit: I know that the file is locked by the devenv.exe process that results in the above error because if I restart the VS, then the problem would go away, but is there anyway to fix this without actually restarting the VS?

Upvotes: 3

Views: 6032

Answers (4)

user5638959
user5638959

Reputation: 1

I seen this problem , I went to the debug folder of my project in VBprojects folder and deleted the files , then I rebuild the application and it works

Upvotes: 0

Rob King
Rob King

Reputation: 94

FWIW, this bug has been around for YEARS and MS still haven't fixed it. Just google "MSB3021" to see all the posts about it.

Upvotes: 2

Metro Smurf
Metro Smurf

Reputation: 38335

I've run into this in the past and as Sam has suggested, restarting VS seems to work, though not what you're looking for.

However, there is a thread on the MSDN forums, "Unable to copy from obj\debug to bin\debug", which provides a couple of suggestions:

Option 1

Create a pre-build action in your project by going to project properties (right-click on the project in the solution explorer, and select the Properties option), select the Build Events tab. Add this code:

if exist "$(TargetPath).locked" del "$(TargetPath).locked" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"

This copies the file to a different name, and allows the build to continue successfully.

With a subsequent follow up of:

But one small improvement is neccessary to let the hack work also if the build is run from scratch, e.g. after clean:

if exist "$(TargetPath).locked" del "$(TargetPath).locked" if not exist "$(TargetPath).locked" if exist "$(TargetPath)" move "$(TargetPath)" "$(TargetPath).locked"

Option 2

I had a similar problem and I solved it excluding from the project in [Source Repository of Choice] the folders bin and obj.

HTH's

Upvotes: 6

Sam Post
Sam Post

Reputation: 3821

I've seen this problem too before, if I remember right I just closed Visual Studio and started it back up again. If you know the process which is locking your file, you need to find a way to a) get the process to release the lock, b) kill the process

Upvotes: 1

Related Questions