Web Deployment to IIS with .Net Core

Steve Ellwood
3 min readJul 29, 2021

I have a web service that gets occasionally updated. This service was originally written for .net 1.1 and was later upgraded to .net 3.5 and now .net 4.7.1. It’s now being converted to .net core. (LTS)

For all these years, this application has been deployed to a file share as for this particular case it has been sufficient and effective. The only issue was about 10 minutes of downtime but this could be easily scheduled in to have minimal impact.

Now that we are upgrading to .net core we have hit a slew of issues. Some of these may be caused by IIS as we have updated the server to Windows Server 2019.

File share deployment

The first issue is that Visual Studio errors when using the file share deployment. These errors mostly revolve around some files being in use. I don’t know for sure what’s using these files, but I know nothing is using the web service, so I can only assume it’s IIS or dotnet that’s locking the files. Clearly this makes automated deployment difficult. Manually you can delete the files concerned with few issues!

Web Deploy

Web Deploy has been around for many years now so I would expect it to be a mature technology. I’ve never used it before as I haven’t needed it because it makes things more complicated that I need. My assumptions about being more complex proved to be accurate. Firstly it wouldn’t install properly on the server, it kept erroring out. When this was eventually resolved Visual Studio didn’t like it, after a long pause it simply refused to publish, it did less than the file share option. It turns out that even if it had not refused it probably would have hit the same issues as the fileshare deployment

Unlocking the Files

One way of unlocking files is to add app_offline.htm to the website. This immediately turns it off. In my case that wouldn’t be too much of a problem as I’ve now started to use Blue/Green deployment and would be deploying to the one that wasn’t live, the irritation is that it’s an extra step and yet more work to get it fully automated but it’s a start. More information is here.

Alternatively you can simply stop the website and then publish. This works in the same way as it used to so is quite familiar and possibly a bit simpler than adding and removing files.

Deploying to a Farm

Now that we know how to deploy the files, if you are using a farm e.g. for load balancing or for blue/green deployment. I’ll explain for the load balancing scenario but the principle for a blue/green deployment are essentially identical.

Using IIS Manager go to Monitoring and Management for the farm, when you right click on the server that you want to deploy to you should see something like the following

IIS Farm Monitoring and Management options

The first step is to Disallow new Connections, this drains the app pool and you can Make the Server Unavailable Gracefully. When this is done, you can deploy using the technique described above, in my case I stop the website as I am already in IIS Manager. The final step is to make the server available again and everything should be back to normal.

If you’re like me and don’t want to do this manually, then it can be scripted and that will be the subject of a future blog.

--

--

Steve Ellwood

Senior Integrations Officer at Doncaster Council Any views expressed are entirely my own.