简体   繁体   English

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

[英]Problems with deploy ASP.NET 5 (ASP.NET Core) app to Azure

I have an app on ASP.NET 5 (CoreCLR) and I try to publish it to the Microsoft Azure. 我在ASP.NET 5(CoreCLR)上有一个应用程序,我尝试将其发布到Microsoft Azure。 I using free Web App (not VDS) 我使用免费的Web App (不是VDS)

I am publishing app using Visual Studio 2015 Publish->Microsoft Azure and following this instructions . 我正在使用Visual Studio 2015 Publish->Microsoft Azure发布应用程序并遵循此说明

But when I publish it and try to open, I see just non-stop loading of empty page. 但是当我发布它并尝试打开时,我看到只是不间断加载空页面。 I enabling logging and view the log (stdout.log) from Azure and there was only: 我启用日志记录并从Azure查看日志(stdout.log),并且只有:

'"dnx.exe"' is not recognized as an internal or external command,

operable program or batch file. 可操作程序或批处理文件。

Also I tried to do Continiusly publishing with git. 我还尝试用git进行Continiusly publishing During push, It started restoring packages and failed with error no disk space available . 在推送期间,它开始恢复软件包并因错误而no disk space available而失败。

Is there any way to publish ASP.NET 5 app to the Azure Web App? 有没有办法将ASP.NET 5应用程序发布到Azure Web App?

Short Answer 简答

But when I publish it and try to open, I see just non-stop loading of empty page. 但是当我发布它并尝试打开时,我看到只是不间断加载空页面。

This happens when our app fails to publish the runtime ( dnx.exe ) with the application. 当我们的应用程序无法使用应用程序发布运行时( dnx.exe )时会发生这种情况。

Discussion 讨论

There are several ways to publish ASP.NET Core rc1 apps to an Azure Web App. 有几种方法可以将ASP.NET Core rc1应用程序发布到Azure Web App。 These include continuous deployment with Git and publishing with Visual Studio. 其中包括使用Git进行持续部署以及使用Visual Studio进行发布。 Post your repository's contents for specific help. 发布存储库的内容以获取特定帮助。

The example is an ASP.NET Core rc1 app, deployed to an Azure Web App, via GitHub continuous deployment. 该示例是一个ASP.NET Core rc1应用程序,通过GitHub持续部署部署到Azure Web App。 These are the vital files. 这些是至关重要的文件。

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

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

Add the HttpPlatformHandler . 添加HttpPlatformHandler Configure it to forward all requests to a DNX process. 将其配置为将所有请求转发到DNX进程。 In other words, tell the Azure Web app to use 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>

app/project.json 应用程序/ project.json

Include a dependency on the Kestrel server. 在Kestrel服务器上包含依赖项。 Set a web command that will startup Kestrel. 设置将启动Kestrel的web命令。 Use dnx451 as the target framework. 使用dnx451作为目标框架。 See below for the additional work to target dnxCore50 . 请参阅下文,了解针对dnxCore50的其他工作。

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

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

  "frameworks": {
    "dnx451": { }
  }
}

app/Startup.cs 应用程序/ Startup.cs

Include the Configure method. 包括Configure方法。 This one adds an extremely simple response handler. 这个添加了一个非常简单的响应处理程序

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.");
            });
        }
    }
}

.deployment (optional) .deployment (可选)

If your app is not in the repositories root directory, tell the Azure Web App which directory contains the app. 如果您的应用程序不在存储库根目录中,请告知Azure Web App哪个目录包含该应用程序。

[config]
project =  app/

global.json (optional) global.json (可选)

If you would like to target .NET Core, tell Azure that we want to target it. 如果您希望以.NET Core为目标,请告诉Azure我们要将其作为目标。 After adding this file, we can either replace (or complement) the dnx451 entry in our project.json with dnxCore50 . 添加此文件后,我们可以替换(或补充)的dnx451在我们与project.json进入dnxCore50

{
  "sdk": {
    "version": "1.0.0-rc1-update1",
    "runtime": "coreclr",
    "architecture": "x64"
  }
}

Firstly, yes, you can happily run ASP.Net 5 core apps on Azure, but there are some gotchas. 首先,是的,您可以愉快地在Azure上运行ASP.Net 5核心应用程序,但有一些问题。

I don't know why it doesn't work when you publish from Visual Studio itself (so why is he posting an answer I hear you ask...), but here are some things to have a look at; 知道为什么当你从Visual Studio本身发布时它不起作用(所以为什么他发布了我听到你问的答案......),但这里有一些东西可以看一看;

  • Try running in IIS locally (rather than kestrel) - just to see if there is a problem. 尝试在本地运行IIS(而不是红隼) - 只是为了查看是否存在问题。 For example, you need a Web.config with some settings or you need the app.UseIISPlatformHandler in startup.cs. 例如,您需要具有某些设置的Web.config, 或者您需要startup.cs中的app.UseIISPlatformHandler。
  • Have a look at your global.json file. 看看你的global.json文件。 It shouldn't matter when you publish from Visual Studio but it won't hurt to set this correctly. 当您从Visual Studio发布,但它不会伤害到正确设置此它不应该的问题。 You can do something like this: 你可以这样做:

.

{
  "sdk": {
    "version": "1.0.0-rc1-update1",
    "runtime": "coreclr",
    "architecture": "x64"
  }
}

Regarding continous publishing - that is a known problem with free and shared sites and one that cost me a few hours. 关于连续发布 - 这是一个已知的免费和共享网站问题,而且花费了我几个小时。 Basically, when you are deploying by this mechanism and you specify corecelr, the entire runtime is re-installed from Nuget and that takes up nearly 1GB (the allowance for free and shared sites). 基本上,当您通过此机制进行部署并指定corecelr时,整个运行时将从Nuget重新安装,并占用近1GB(免费和共享站点的容量)。 Add a few NPM packages and you are over the limit and, hey presto, you can't deploy. 添加一些NPM包,你已超出限制,嘿,你无法部署。 @shanselman discussed it recently on one of his podcasts. @shanselman最近在他的一个播客上讨论过它。 It's not actually the runtime binaries that take up all the space, but because we are in build mode, all the documentation XML files are installed as well, because Nuget doesn't know you are not in a development environment, and they are huge. 实际上并不是占用所有空间的运行时二进制文件,但由于我们处于构建模式,因此也安装了所有文档XML文件,因为Nuget不知道您不在开发环境中,而且它们非常庞大。 Right now, the simplest answer if you want to use continuous publishing on a free or shared site is to also include the full runtime in your project.json and set your global.json to use the full CLR instead of the coreclr. 现在,如果您想在免费共享站点上使用连续发布,最简单的答案是在project.json中包含完整的运行时,并将global.json设置为使用完整的CLR而不是coreclr。 Just very frustrating. 非常令人沮丧。

I was having the same problem. 我遇到了同样的问题。 This answer solved the issue. 这个答案解决了这个问题。

When creating a new project with the asp.net core template the global.json file was part of my API project, but it was also referenced in the Solution Items folder. 使用asp.net核心模板创建新项目时, global.json文件是我的API项目的一部分,但它也在Solution Items文件夹中引用。 When published to an Azure API app, two global.json files were deployed: 发布到Azure API应用程序时,部署了两个global.json文件:

  1. In the /approot/global.json /approot/global.json
  2. In the /approot/src/MyAPI/global.json /approot/src/MyAPI/global.json

I moved the global.json file out of the project folder to the solution root, and re-added a reference back into the Solution Items folder. 我将global.json文件从项目文件夹中移出到解决方案根目录,然后将引用重新添加回Solution Items文件夹。

When deployed only the /approot/global.json file was then deployed, resolving the issue. 部署后,只部署了/approot/global.json文件,解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM