azure - MSDeploy 到 Azure Web 应用程序 : Could not connect to the remote computer using the specified process ("Web Management Service")

标签 azure msbuild azure-web-app-service msdeploy azure-devops

我们使用以下脚本在 VSO/VSTS Build (vNext) 中使用 MSBuild MSDeploy 发布到我们的 Azure Web App。这效果很好。

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

MSDeploy 上的 VSTS 生成错误:

Publishing with publish method [MSDeploy] Executing command ["C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:IisApp='C:\a\8b0700fff\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 门户自定义域设置:

Azure Portal Custom domain

发布脚本:

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 ”,这不是 SCM URL。 SCM URL 应如下所示:“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。

关于azure - MSDeploy 到 Azure Web 应用程序 : Could not connect to the remote computer using the specified process ("Web Management Service"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34435909/

相关文章:

c# - 检查 Web 应用程序配置设置 - Microsoft Azure

azure - 如何在 Program.cs 中检索 Azure 应用程序配置服务设置

azure 逻辑应用: not corrently checking empty check

javascript - 如何设置队列输出的过期时间 - Azure function js

tfs - 如何避免在不使用忽略属性的 mstest 中运行测试?

asp.net - 通过 MSBuild 构建解决方案时出现 ASPNETCOMPILER 错误,但在 Visual Studio 中成功

azure - 如何创建 access_token 来为用户而不是服务主体访问 ARM API

c# - 为什么 Azure Function 应用程序中使用的 Microsoft.Azure.WebJobs.HttpTriggerAttribute 是参数属性而不是方法属性?

visual-studio-2010 - Visual Studio 2010 无法加载导入了 <ProjectConfiguration> 元素的项目

azure - Visual Studio 2022 发布窗口未检测身份验证状态