I am using octopus deployment with teamcity. In many cases deployment fails because "The process cannot access the file or dll because it is being used by another process. How to write a script to fix this problem. Please guide.
-
possible duplicate of [Powershell script to check application that's locking a file?](http://stackoverflow.com/questions/958123/powershell-script-to-check-application-thats-locking-a-file) – CB. May 24 '13 at 10:27
-
What have you attempted so far? – alroc May 24 '13 at 11:09
2 Answers
I'm reading into your question a little here, but it sounds to me that you're trying to deploy a website and it's failing, because the IIS worker process is using the files - what you want to do is recycle the application pool of the website before you deploy, or, if it's a high traffic website, stop the website, do the deploy, then start the website.

- 4,258
- 2
- 23
- 23
Within powershell, I found a few options available.
Get-Process
Can be used but it's shortcoming is that it only works with .dlls and some other code related file types.Microsoft's SysInternals Suite has
handle.exe
that can be used but you need to make sure the machine has SysInternals on it.
I ran into this issue and didn't like any of the above options, so wrote an entirely self contained script because I didn't want to depend on SysInternals and needed to target more than just .dll files. This script will identify and kill any process locking a file before making a full recursive copy.
https://github.com/Tikinsin/ForceCopy.ps1/blob/main/ForceCopy.ps1

- 355
- 2
- 8