如何将 ASP.NET Core 应用程序发布到 Azure?
到目前为止,我所做的是创建一个从官方 Azure/Microsoft 文档获取的脚本,该脚本调用 Visual Studio 也使用的 default-publish.ps1 脚本。该脚本如下所示:
param($websiteName, $packOutput)
$website = Get-AzureWebsite -Name $websiteName
# get the scm url to use with MSDeploy. By default this will be the second in the array
$msdeployurl = $website.EnabledHostNames[1]
$publishProperties = @{'WebPublishMethod'='MSDeploy';
'MSDeployServiceUrl'=$msdeployurl;
'DeployIisAppPath'=$website.Name;
'Username'=$website.PublishingUsername;
'Password'=$website.PublishingPassword}
$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
现在,如果您提供 Azure 网站名称和 dotnet 发布工件,此脚本将调用 default-publish.ps1 脚本。我已将 default-publish.ps1 脚本更新为 repo 中当前的内容。 .
问题是,当我发布到 Azure 时,返回 502 Bad Gateway 错误。即使使用新工具更新创建的项目,我似乎也无法将其正确发布到 Azure。
最佳答案
你有 web.config 吗?它是否包含在您的project.json中,如下所示:
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
}
您的 web.config 将如下所示:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule"
resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%"
stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"
forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
注意:环境变量 LAUNCHER_PATH 和 LAUNCHER_ARGS 可能是问题的根源。您正在尝试启动 Visual Studio 运行的发布脚本,Visual Studio 可能会在运行脚本之前设置环境中的值。
为了在 Azure VM 上启动并运行 RC2 站点,我必须将该行更改为如下所示:
<aspNetCore processPath="dotnet" arguments="./YourAppEntryPoint.dll"
stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"
forwardWindowsAuthToken="false"/>
尝试使用显式值设置 web.config。如果您的部署有效,那么您就知道是缺少 ENVVARS 造成了困惑。
关于powershell - 通过 PowerShell 将 ASP.NET Core 应用程序发布到 Azure 在 Azure 中收到 502(错误网关),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37414657/