In this tutorial, you will learn how to fix a locked file error you will likely encounter when you start publishing a Umbraco 9 site. When you encounter this error it is very annoying 🤬
The first time you publish everything works as expected. The second time you publish.... things do not go according to plan, Visual Studio throws a wobbly and you encounter some form of locked file error. If you want to get rid of this gear grinding issue, this is the tutorial for you 🔥🔥🔥
Manually Unlocking The Files
There are a number of standard ways of unlocking the files, performing an IIS reset, rebooting your PC, using TaskManager and killing the task called .NET core Host
. These fixes work but they are not optimal. Having to manually make a fix each time will grate very quickly 😒
A better manual way to fix resolve the issue is to create a file called App_Offline.htm
within your website root. IIS has an in-built feature where if a file called App_Offline.htm
exists within the root folder, IIS will route all traffic to the HTML file while unlocking any currently running processes.
Having to add this file manually is a pain so we need to automate it. If you create an empty file the website will throw a 503, if you create a valid HTML page IIS will render that page.
Automatically Unlocking The Files
There are two ways to do this, the first is useful for overcoming local locking. The first fix is to add a pre
and post
build step within your websites csproj
file. During a build, MSBuild will create a file and then remove it after the published has finished. This should resolve the locking and unlocking errors:
The other way to automate this process is the publish profile. When you create a Publish
profile within Visual Studio, a file will be created within your webroot within a folder called Properties
. Within this file, you can add a parameter called EnableMSDeployAppOffline
.
When enabled, during a publish App_Offline.htm
will be created before publish and then it will automatically be removed afterwards. In this manner, that nasty locking issue will be gone 💥
Happy Coding 🤘