A frustrating experience making this work caused me to write this guide. What happens is your output may be missing some of the files needed, or be structured incorrectly, for IIS to launch your app. The issue can arise for different reasons.
Archive contains root directory.
When you create your zip file, make sure you are not archiving the root folder. What happens is your /home/site/wwwroot directory looks like:
/home/site/wwwroot
--RootFolder
--LaunchFile
When IIS is expecting
/home/site/wwwroot
--LaunchFile
This is easy to fix by adding includeRootFolder: false to the ArchiveFiles@2 task.
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
includeRootFolder: false
Alternatively, if using the Web UI in the Root folder or file to archive section ensure that
Prepend root folder name to archive paths is not checked.
Build vs Publish
Using the .NET Core task to build the project or solution can result in output that will not work in the /home/site/wwwroot directory. The key here is to choose the publish option, not the build option. build was working for us and then did not for one of our projects. Changing to publish made it work again.
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: 'MyProj/MyProj.csproj'
arguments: '--output $(Build.BinariesDirectory)/WhereYouWantFilesForNextStep --configuration Release'
Instead, use the publish command.
steps:
- task: DotNetCoreCLI@2
inputs:
command: publish
arguments: '--configuration Release -o $(Build.BinariesDirectory)/WhereYouWantFilesForNextStep'
Zip File is not Mounted
Zip archives deployed to Azure are stored in
Directory of D:\home\data\SitePackages
11/03/2021 06:24 PM <DIR> .
11/03/2021 06:24 PM <DIR> ..
11/03/2021 04:24 PM 66,278,978 20211103162437.zip
11/03/2021 06:24 PM 73,799,022 20211103182443.zip
11/03/2021 06:24 PM 18 packagename.txt
And, if the following Application Setting is provided:
WEBSITE_RUN_FROM_PACKAGE = 1
Then IIS will mount the zip archive specified in packagename.txt to the D:\home\site\wwwroot.
D:\home\data\SitePackages>cat packagename.txt
20211103182443.zip
Note that 20211103182443.zip is the name of one of the .zip file listed in D:\home\data\SitePackages directory. Now if WEBSITE_RUN_FROM_PACKAGE is toggled the contents of D:\home\site\wwwroot will change.
Useful Resources
Additional reading is available at Microsoft Docs: Run your app in Azure App Service directly from a ZIP package.
If you want to examine the contents of the zip file directly, PowerShell will work in the console provided at App Service > Development Tools > Console and has access to the Unzip command.
D:\home\data\SitePackages>PowerShell Unzip -l 20211103162437.zip
Archive: 20211103162437.zip
Length Date Time Name
--------- ---------- ----- ----
25600 2013-07-17 23:18 AForge.Genetic.dll
...