Web Deploy Publish Fails Because a File is Locked or In UseThis article shows you how to fix a Web Deploy publish that fails because a file on the web server, usually a DLL, is locked or in use. It applies to ASP.NET and .NET Core websites published with Web Deploy from Visual Studio, GitHub or the command line. When this happens the publish stops with an error similar to one of these:
The reason is that your website is running. While it runs, the web server has your application files open in memory, which locks them, so Web Deploy can not overwrite them with the new versions. Nothing is wrong with your website or with Web Deploy, the application just needs to be stopped while the new files are published. Restarting the Application Pool does not fix this. After a restart the website starts again on the next visit and locks the files again before your publish runs. The application has to stay stopped until the publish has finished. There are two ways to do this. Method 1: Let Web Deploy take the application offlineWeb Deploy can take your application offline for you at the start of each publish and bring it back at the end. You set this once in your project and every publish after that looks after itself. In Visual Studio, open your publish profile. This is the .pubxml file in the Properties\PublishProfiles folder of your project. Find the PropertyGroup section and add the following setting to it:
Once completed your publish profile should look something similar to the example below:
If you publish from the command line or from GitHub using msbuild or dotnet, add the same setting to the command:
If you call msdeploy directly, add the following to the command:
With this setting, Web Deploy places a file named app_offline.htm in your website at the start of the publish. This tells the web server to stop your application and release its files. When the publish has finished Web Deploy removes the file and your website starts again on the next visit. Two things to be aware of: 1. The application can take a few seconds to release its files, so now and then a publish may still fail on a locked file. Publish again, and if it keeps failing use Method 2 below. 2. If a publish fails part way through, the app_offline.htm file can be left behind and your website will stay offline. If your website does not come back after a failed publish, delete app_offline.htm from your website's public_html folder using FTP or the Control Panel File Manager. Method 2: Stop the Application Pool, publish, then start it againThis method always works, as your application is fully stopped before you publish. Your website will be offline from when you stop the Application Pool until you start it again, so remember the last step. 1. Log into your Hosting Control Panel. 2. Click the Web Sites icon option 3. Click on the website name that you are publishing to, to enter the website properties 4. In the website properties click the App Pool Status Stop Icon and wait for the Application Pool to stop, which can take up to 60 seconds ![]() 5. Publish your website using Web Deploy 6. Once the publish has finished, start your website again by clicking the App Pool Status Start Icon ![]() Related articlesHow to Enable Web Deploy Publishing your Application using Web Deploy How to Restart Your Website Application Pool Back To Hosting Knowledgebase Menu |
Fully managed or self-managed, from our own solar powered data centre.
Web Wiz® is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.
Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, €, prices shown as a guideline only.
Copyright ©2001-2026 Web Wiz® Ltd. All rights reserved.