MSDeploy 到 Azure Web App:无法使用指定进程连接到远程计算机 ("Web Management Service")

MSDeploy to Azure Web App: Could not connect to the remote computer using the specified process ("Web Management Service")

我们使用下面的脚本在 VSO/VSTS 构建 (vNext) 中使用 MSBuild MSDeploy 发布到我们的 Azure Web 应用程序。这很好用。

但是,当(通过 Azure 门户)将 Azure Web App 分配给自定义域时,发布失败。

MSDeploy 上的 VSTS 构建错误:

Publishing with publish method [MSDeploy] Executing command ["C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:IisApp='C:\ab0700fff\MrProjectMain\Api\wwwroot' -dest:IisApp='myproject-prod-webapp',ComputerName='https://myproject-prod-webapp.azurewebsites.net/msdeploy.axd',UserName='$myproject-prod-webapp',Password='{PASSWORD-REMOVED-FROM-LOG}',IncludeAcls='False',AuthType='Basic' -verb:sync -enableLink:contentLibExtension -retryAttempts:2 -disablerule:BackupRule]
[error]Error Code: ERROR_COULD_NOT_CONNECT_TO_REMOTESVC
[error]More Information: Could not connect to the remote computer ("myproject-prod-webapp.azurewebsites.net") using the specified process ("Web Management Service") because the server did not respond. Make sure that the process ("Web Management Service") is started on the remote computer. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_COULD_NOT_CONNECT_TO_REMOTESVC. [error]Error: The remote server returned an error: (403) Forbidden.
[error]Error count: 1.

Azure 门户自定义域设置:

发布脚本:

param($websiteName, $packOutput)

$website = Get-AzureWebsite -Name $websiteName
$msdeployurl = $website.EnabledHostNames[1]

$publishProperties = @{'WebPublishMethod'='MSDeploy';
                        'MSDeployServiceUrl'=$msdeployurl;
                        'DeployIisAppPath'=$website.Name;
                        'Username'=$website.PublishingUsername;
                        'Password'=$website.PublishingPassword;
                        'SkipExtraFilesOnServer'='False';
                        'AllowUntrustedCertificate'='True'}

Write-Output "Publishing web app..."
$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"
. $publishScript -publishProperties $publishProperties  -packOutput $packOutput

问题在这里:

$msdeployurl = $website.EnabledHostNames[1]

默认情况下,MSDeploy SCM URL 是 EnabledHostNames 数组中的第二个。所以它默认工作。但是一旦您对网络应用程序进行了一些更改,它可能就无法正常工作。根据您提供的日志,MSDeploy 正在尝试连接到“https://myproject-prod-webapp.azurewebsites.net/msdeploy.axd", this is not a SCM URL. The SCM URL should like this: "https://myproject-prod-webapp.scm.azurewebsites.net/msdeploy.axd”。所以你现在需要检查什么是正确的 scm URL 数组号。您可以在 PowerShell 脚本中添加如下代码以查看哪个是 scm URL,然后相应地更新脚本。

Write-Output $website.EnabledHostNames[0]
Write-Output $website.EnabledHostNames[1]
Write-Output $website.EnabledHostNames[2]
...

您也可以参考 this article 更新您的脚本以自动获取正确的 SCM url。