Friday, August 2, 2019

Deploy Visual Studio Solution To Azure Web App Using PowerShell

Prerequisites
You will learn
  • About PowerShell commands Regarding Azure Web app.
  • How to create Publish Visual Studio Solution as a File System.
  • How to publish local zip file to Azure Web app.
Getting started with Azure PowerShell for Web app
To learn about how to Configure Azure subscription to PowerShell & how to create, check availability of the name, delete & run Web app on Microsoft Azure, please refer to:
Deploying an Azure Web app
Step 1
Create an Azure Web app, using PowerShell.
New-AzureWebsite -Location "South India" -Name "azurewebapppsdemo"
Azure
Note
Wait for a few seconds to create a Web app.
Step 2
Start Visual Studio & create a New Project.

Azure
Step 3

Choose “Empty” ASP.NET Template & click OK button.
Azure 
Step 4
Right click on the Project Name -> Add -> New Item.

Azure
Step 5
Add HTML page file & name it as index.html.

Azure
Note
You can also add Web form or any other page.
Step 6
Add some text into index.html file. 
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <title></title>  
  5.     <meta charset="utf-8" />  
  6. </head>  
  7. <body>  
  8.     <h1>Azure Web App PowerShell Demo</h1>  
  9. </body>  
  10. </html>   
Azure

Step 7


Now, right-click on the project name & click Publish option.

Azure
Step 8

The different options are available as a publish target but we are selecting Custom option.

Azure
Enter Profile name. Ex. WebApp.

Azure
Change Publish method to File System. Also, set Target location.

Azure
Create new folder to publish the project.

Azure
Azure
Click Next button.
Configuration: Release.
Check Delete all the existing files prior to publish option.

Azure
Click Publish button.

Azure
Wait for a  few seconds to publish the project.

Azure
Step 9
Run PowerShell & enter the command given below to build the project.
msbuild E:\Azure\webapp01\WebApplication1\WebApplication1.sln /p:DeployOnBuild=true /p:PublishProfile=WebApp /p:VisualStudioVersion=14.0

Azure
Note
Enter the solution path with an extension like .sln,
  • DeployOnBuild=true -> Deploy on Build.
  • PublishProfile=WebApp -> Enter publish profile name.

    Azure
  • VisualStudioVersion=14.0 -> This project is developed, using Visual Studio 2015, so enter Visual Studio version.
If “Build Succeeded”, go to next step, else please check for the error.

Azure
Step 10
Now, we will upload or publish the local folder to Cloud.
$source = "E:\Azure\webapppublish"

Azure
Note
Project published folder path as a source.
$destination = "E:\Azure\webapppublish.zip"

Azure
Note
Enter new .zip file name as a destination.
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory($source,$destination)

Azure
Note
Create a new directory, using the command
Now you have .zip file or website package file to publish as AzureWebApp
Publish-AzureWebsiteProject -Package E:\Azure\webapppublish.zip -Name azurewebapppsdemo

Azure
Step 11
Website content successfully deployed on Ccloud. Now, run AzureWebApp
Show-AzureWebsite -Name azurewebapppsdemo

Azure
Automatically, the Browser will open Azure Web app.

Azure

No comments:

Post a Comment

Lab 09: Publish and subscribe to Event Grid events

  Microsoft Azure user interface Given the dynamic nature of Microsoft cloud tools, you might experience Azure UI changes that occur after t...