将ASP.NET 5(ASP.NET Core)应用程序部署到Azure的问题

Ale*_*kov 9 c# azure azure-web-sites asp.net-core

我在ASP.NET 5(CoreCLR)上有一个应用程序,我尝试将其发布到Microsoft Azure.我使用免费Web App(不是VDS)

我正在使用Visual Studio 2015发布应用程序Publish->Microsoft Azure并遵循此说明.

但是当我发布它并尝试打开时,我看到只是不间断加载空页面.我启用日志记录并从Azure查看日志(stdout.log),并且只有:

'"dnx.exe"' is not recognized as an internal or external command,
Run Code Online (Sandbox Code Playgroud)

可操作程序或批处理文件.

我还试着Continiusly publishing用git 做.在推送期间,它开始恢复包并因错误而失败no disk space available.

有没有办法将ASP.NET 5应用程序发布到Azure Web App?

Sha*_*tin 5

简答

但是当我发布它并尝试打开时,我看到只是不间断加载空页面.

当我们的应用程序无法使用应用程序发布runtime(dnx.exe)时会发生这种情况.

讨论

有几种方法可以将ASP.NET Core rc1应用程序发布到Azure Web App.其中包括使用Git进行持续部署以及使用Visual Studio进行发布.发布存储库的内容以获取特定帮助.

该示例是一个ASP.NET Core rc1应用程序,通过GitHub持续部署部署到Azure Web App.这些是至关重要的文件.

app/
    wwwroot/
        web.config
    project.json
    startup.cs
.deployment           <-- optional: if your app is not in the repo root 
global.json           <-- optional: if you need dnxcore50 support
Run Code Online (Sandbox Code Playgroud)

应用程序/ wwwroot的/ web.config中

添加HttpPlatformHandler.将其配置为将所有请求转发到DNX进程.换句话说,告诉Azure Web应用程序使用DNX.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="httpPlatformHandler" 
           path="*" verb="*" 
           modules="httpPlatformHandler" 
           resourceType="Unspecified"/>
    </handlers>
    <httpPlatform 
         processPath="%DNX_PATH%" 
         arguments="%DNX_ARGS%" 
         stdoutLogEnabled="false" 
         startupTimeLimit="3600"/>
  </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

应用程序/ project.json

在Kestrel服务器上包含依赖项.设置一个web启动Kestrel 的命令.使用dnx451为目标的框架.请参阅下面的目标附加工作dnxCore50.

{
  "dependencies": {
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnx451": { }
  }
}
Run Code Online (Sandbox Code Playgroud)

应用程序/ Startup.cs

包括Configure方法.这个添加了一个非常简单的响应处理程序

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;

namespace WebNotWar
{
    public class Startup
    {
        public void Configure(IApplicationBuilder app)
        {
            app.Run(async (context) =>
            {
                await context.Response.WriteAsync(
                    "Hello from a minimal ASP.NET Core rc1 Web App.");
            });
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

.deployment(可选)

如果您的应用程序不在存储库根目录中,请告知Azure Web App哪个目录包含该应用程序.

[config]
project =  app/
Run Code Online (Sandbox Code Playgroud)

global.json(可选)

如果您希望以.NET Core为目标,请告诉Azure我们要将其作为目标.添加此文件后,我们可以替换(或补充)的dnx451在我们进入project.jsondnxCore50.

{
  "sdk": {
    "version": "1.0.0-rc1-update1",
    "runtime": "coreclr",
    "architecture": "x64"
  }
}
Run Code Online (Sandbox Code Playgroud)