AZ-204 practice question 34 of 35

You are preparing to deploy an ASP.NET Core website to an Azure Web App from a GitHub repository. The website includes static content generated by a…

Full set: 489 questions

Domain Develop Azure compute solutions

You are preparing to deploy an ASP.NET Core website to an Azure Web App from a GitHub repository. The website includes static content generated by a script. You plan to use the Azure Web App continuous deployment feature. You need to run the static generation script before the website starts serving traffic. What are two possible ways to achieve this goal? Each correct answer presents a complete solution. NOTE: Each correct selection is worth one point.
Answer options
A: Create a file named .deployment in the root of the repository that calls a script which generates the static content and deploys the website. Correct answer
B: Add a PreBuild target in the websites csproj project file that runs the static content generation script. Correct answer
C: Create a file named run.cmd in the folder /run that calls a script which generates the static content and deploys the website.
D: Add the path to the static content generation tool to WEBSITE_RUN_FROM_PACKAGE setting in the host.json file.
Correct Answer:
A. Create a file named .deployment in the root of the repository that calls a script which generates the static content and deploys the website.; B. Add a PreBuild target in the websites csproj project file that runs the static content generation script.
Explanation

To run a script before an ASP.NET Core website starts during an Azure App Service continuous deployment, you can customize the build and deployment process managed by Kudu, the App Service deployment engine.
1. Creating a .deployment file in the repository's root allows you to specify a custom deployment script. Within this script, you can add commands to generate static content before the standard build and deployment steps are executed.
2. Adding a PreBuild target to the .csproj project file integrates the script execution directly into the MSBuild process. Since Kudu uses MSBuild to build .NET applications, the script will run on the build server, and its output will be included in the final deployment package.

Why Incorrect

C. The run.cmd file is used for defining Azure WebJobs, which are background processes, not for customizing the main website's deployment workflow.
D. WEBSITERUNFROMPACKAGE is an application setting for running an app from a zip package. host.json is a configuration file for Azure Functions, not Web Apps.

References

1. Answer A: Microsoft Docs. (2023). Customize deployments - Azure App Service. Section: "Deployment script". This document explains that you can create a .deployment file to point to a custom deployment script, allowing you to add custom logic like pre-build steps.

Reference: https://learn.microsoft.com/en-us/azure/app-service/deploy-customize-scripts#deployment-script

2. Answer A & General Kudu Process: Kudu Project Wiki. (n.d.). Customizing deployments. This official wiki for the Kudu engine details how to use the .deployment file and deploy.cmd/.sh to hook into and modify the deployment process, including adding steps before the build.

Reference: https://github.com/projectkudu/kudu/wiki/Customizing-deployments

3. Answer B: Microsoft Docs. (2023). MSBuild targets. This document describes how to use MSBuild targets like PreBuildEvent or custom targets with BeforeTargets="Build" to execute commands before the main build process, which is leveraged by Kudu during deployment.

Reference: https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-targets?view=vs-2022 (See section "Use the BeforeTargets and AfterTargets attributes").

4. Answer C (Incorrect): Microsoft Docs. (2023). Run background tasks with WebJobs in Azure App Service. This page shows that run.{cmd|bat|exe|ps1|sh|php|py|js} is the convention for executable scripts within a WebJob, not for the main site deployment.

Reference: https://learn.microsoft.com/en-us/azure/app-service/webjobs-create#create-a-manually-triggered-webjob

5. Answer D (Incorrect): Microsoft Docs. (2023). Run your app in Azure App Service directly from a ZIP package. This document clarifies that WEBSITERUNFROMPACKAGE is an application setting for mounting a package, not executing a script.

Reference: https://learn.microsoft.com/en-us/azure/app-service/deploy-run-package

Scroll to Top