Powershell command Publish-AzWebApp not publishing apllication

Viewed 162

I have a .Net 6 Web API application, I am able to publish it via Visual Studio 2022 to Azure Application service and then use the application.

Now I want to automate it. My powershell creates a zip file with all the necessary files inside.

Then I call

Publish-AzWebApp -ResourceGroupName  MyResourceGroup -Name MyWebApi -ArchivePath D:\projects\MyWebApi\publish\8044a70f-f3fc-4271-b37a-f0b2658d9192.zip

But after it finishes I go to Azure ftp and wwwroot folder is empty and the application does not work.

Am I using the cmdlet the wrong way?

2 Answers

Created a .NET Core 6 Web Application in Visual Studio 2022 and made to the Zip File.

  • Created the App Service using PowerShell Commands:

enter image description here

  • Deployed the above Web Application to this App Service using the Command from the local Windows PowerShell:

enter image description here

enter image description here

Updated Answer:

You can deploy using Cloud Shell, but Azure Cloud Shell has some limitations.

AzurecloudShell

We need to upload the Zip File to Azure Clouddrive if using the Azure Cloud Shell and then deploy the Web App to the particular app service from that Clouddrive location.

This is how to deploy web api to Azure from local directory in zip file

[xml]$publishingProfileXMl = Get-AzWebAppPublishingProfile -ResourceGroupName $resourceGroupName -Name $webAppName -Format "WebDeploy"

$userName = $publishingProfileXMl.publishData.publishProfile.userName[0]
$password = $publishingProfileXMl.publishData.publishProfile.userPWD[0]
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))

$apiUrl = "https://${webAppName}.scm.azurewebsites.net:443/api/zip/site/wwwroot/"
$headers = @{"Authorization"="Basic {0}" -f $base64AuthInfo;}

Write-Host ">------------------------------ Stopping '${webAppName}' Web Application..."
Stop-AzWebApp -ResourceGroupName $resourceGroupName -Name $webAppName
Write-Host ">------------------------------ Publishing '${webAppName}' Web Application..."
Invoke-RestMethod -Uri $apiUrl -Headers $headers -UserAgent $userAgent -Method PUT -InFile $zipPath -ContentType "multipart/form-data"
Write-Host ">------------------------------ Starting '${webAppName}' Web Application..."
Start-AzWebApp -ResourceGroupName $resourceGroupName -Name $webAppName
Related