I am trying to deploy my app as part of a CI/CD script and occasionally get an error because the dlls are still in use when I try and replace them. My script is already copying an app_offline.htm file to the destination folder and waiting 15 seconds. I have also tried deleting the web.config before copying, but still occasionally get a “file being used by another process”.
I was wondering if I could add a service to my app that shuts down the services?
What host are you using? Is this running on IIS, Linux, Windows Service? Depending on this, there are a variety of ways of killing the process running your app as a part of a script that runs on your hosted environment (as opposed to your CI/CD servers).
You could use IApplicationLifetime from within a service to call the StopApplication but I’m not 100% sure what the side effects will be.
Hmm. the fact that you are saying it happens occasionally sounds like an app pool issue of some sort. Maybe a fallback to perform an iisreset or some other way of stopping the apppool before copying the files. Eg (though probably a bit of a nuclear option) as shown in this GitHub Actions.