onemorecupofcoffee
onemorecupofcoffee

Reputation: 2447

how to update self contained asp.net core app and avoid file locks

I have a self hosted asp.net core app deployed and in use in an enterprise environment on Windows Server 2012.

I am looking for a way to automate the update process, I am currently doing this through a bat file but keep getting windows file lock errors where the file cannot be deleted. The process I am following in the bat file is as follows:

  1. kill the dotnet core process for the web app

  2. clear the directory (after sleep for a couple of seconds)

  3. copy the updates over

  4. restart the web app

I am getting the errors in 2 where I try to clear out the existing directory which still has file locks even though I have killed the process - "Cannot delete output file - access is denied".

My question is how can I upgrade the self contained asp.net core web app in place and avoid the file locks? If the site is offline for a few seconds it is not an issue.

Thanks

Upvotes: 4

Views: 1355

Answers (1)

Joel Harkes
Joel Harkes

Reputation: 11671

There a several reasons i can think of that deleting the directory gives access denied errors.

  1. Your process isn't actually stopped yet. I know you can use powershell to await until porcess is stopped. (or check if process is stopped yet and otherwise wait 3 more seconds)
  2. Another process still runs in this folder. (maybe even a command line, or explorer.exe is opened in the folder.)
  3. You need admin rights to delete this folder.
  4. The bat file you are executing executes from this directory, and itself is locking the directory.

Try one of the following:

Try to run powershell to wait like this for example (in commandline):

powershell -Command "Wait-Process -Name MyProcess"` 

(warning you might run into ExecutionPolicy problems)

Tip

Use msdeploy, you can remote execute commands and deploy your application.

You can use pre and post scripts (to stop and start the app) and msdeploy it self will sync the folder/directory for you.

Upvotes: 1

Related Questions