Powershell 命令 Publish-AzWebApp 不发布应用程序

Powershell command Publish-AzWebApp not publishing apllication

我有一个 .Net 6 Web API 应用程序,我可以通过 Visual Studio 2022 将其发布到 Azure 应用程序服务,然后使用该应用程序。

现在我想自动化它。我的 powershell 创建了一个包含所有必要文件的 zip 文件。

那我打电话给

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

但完成后我转到 Azure ftp 并且 wwwroot 文件夹是空的,应用程序无法运行。

我使用 cmdlet 的方式有误吗?

在 Visual Studio 2022 年创建了一个 .NET Core 6 Web 应用程序并制作成 Zip 文件。

  • 使用 PowerShell 命令创建应用服务:

  • 已使用来自本地 Windows PowerShell:
  • 的命令将上述 Web 应用程序部署到此应用程序服务

更新答案:

您可以使用云 Shell 进行部署,但 Azure Cloud Shell 有一些 limitations

如果使用 Azure Cloud Shell,我们需要将 Zip 文件上传到 Azure Clouddrive,然后将 Web 应用程序部署到特定的应用程序服务从那个 Clouddrive 位置。

这是将 web api 从 zip 文件中的本地目录部署到 Azure 的方法

[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