Svenska Svenska | English English

How To Run Your Azure Web App From Zip Package

Johan Åhlén by Johan Åhlén • Updated

Running your Azure Web Apps (App Services) from zip packages is an alternative to the standard deployment model. I will here describe how to setup the package deployment model ("Run From Package") and what the advantages/disadvantages are.

Microsoft describes how to run your app from a zip package. I will try to simplify and expand their description here, also showing you how to automate the deployment.


Running your Azure Web App (App Services) from a zip package gives you a couple of advantages:

However, it also come with some disadvantages/limitations:

Setting Up Package Deployment in Visual Studio

I will describe how to set it up for Visual Studio publishing. It could also be setup for CI/CD in a similar way.

Step 1 - Install Azure CLI (if you don't have it already)

My instructions are based on Azure CLI. You can download it from Microsoft here.

Step 2 - Enable Package Deployment in the Application Settings

First you need to configure your Application Settings. Add a new setting called WEBSITE_RUN_FROM_PACKAGE and set the value to 1. This can either be done in the Azure Portal:

Azure App Service Run From Package

Or you can do it using Azure CLI:

az webapp config appsettings set --resource-group <group-name> --name <app-name> --settings WEBSITE_RUN_FROM_PACKAGE="1"

Step 3 - Create a new Publish Profile in Visual Studio

Choose Folder type and go with the default settings. This will place the output in bin\Release\netcoreapp3.1\publish\ in your project directory.

Azure App Service Folder Publish Profile

Step 4 - Test Manual Package Deployment

Publish your app (using your new Publish Profile). Then go to {Your project folder\bin\Release\netcoreapp3.1\publish} and create a zip-file of all the contents. You can do this in Windows by selecting all files and then Right Mouse Button ≫ Send To ≫ Compressed Folder. Make sure the zip-file has the files directly in the root. Package Deployment zip-file

Then open a command prompt and run the following commands:

az login
az account set --subscription "your subscription name"
az webapp deployment source config-zip --resource-group "group-name" --name "app-name" --src ""

(az login and az account set are only necessary if you are not already logged in through Azure CLI)

Now your zip-file should be uploaded into /home/data/SitePackages on your app services. You can use the SSH or Command Prompt tool in the Azure Portal to check:

Azure App Service /home/data/SitePackages

Note that you also get the packagename.txt file. It contains the name of your zip-file (and will always contain the name of the zip-file used be the webserver).

Your zip-file will be mounted in read-only mode at /home/site/wwwroot. You can test by trying to create a subdirectory there. It should fail.

Step 5 - Automate the Package Deployment

In Visual Studio, find the Folder Publish file. Open it for editing by double-clicking. I also suggest renaming it from FolderProfile to something like PackageDeployment.

In the publish file, add a Target section as in the image below.

This is the code you should put inside the Target tag:

  <Target Name="CustomActionsAfterPublish" AfterTargets="AfterPublish">
    <ZipDirectory SourceDirectory="$(PublishUrl)" DestinationFile="$(MSBuildProjectDirectory)\bin\Release\$(ZipfileName)"/>
    <Exec Command='az account show' WorkingDirectory="C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\" ContinueOnError="true" StandardOutputImportance="low" StandardErrorImportance="low"/>
    <Exec Command='az login' WorkingDirectory="C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\" Condition="$(MSBuildLastTaskResult) == false" StandardOutputImportance="low" StandardErrorImportance="low" />
    <Exec Command='az webapp deployment source config-zip --resource-group "my resource group" --name "my app name" --src $(MSBuildProjectDirectory)\bin\Release\$(ZipfileName)' WorkingDirectory="C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\" />

In the code above:

Run your Publishing Profile. Watch the magic happen!

Further Steps

Keep an eye on the /home/data/SitePackages directory. You may need to delete old zip-files from there, to avoid running out of storage space.

Also, note that your website will not open in your browser after publishing. I haven't looked more into how to open your Site URL automatically since I think it's not that important.

Azure Azure Web Apps App Service on Linux

More about Azure

Running a Blog on Azure Data Lake
Setup Caching on your Azure Storage Blobs
Azure Web App Not Updating After Publish

More about Azure Web Apps

Azure Web App Not Updating After Publish
Azure Linux Publish Error (Web deployment task failed. Could not connect to the remote computer)

More about App Service on Linux

Azure Web App Not Updating After Publish
Azure Linux Publish Error (Web deployment task failed. Could not connect to the remote computer)