将rc2 asp.net核心应用程序发布到azure

时间:2016-03-20 23:13:17

标签: azure asp.net-core kestrel-http-server

我设法将我的应用程序从VSO发布到windows azure。现在的问题是我的应用程序无法在azure上启动此错误(它在本地完美运行):

System.TypeInitializationException: The type initializer for 'Microsoft.AspNetCore.Server.Kestrel.Networking.PlatformApis' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
   at Microsoft.AspNetCore.Server.Kestrel.Networking.PlatformApis..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.Server.Kestrel.Networking.PlatformApis.get_IsWindows()
   at Microsoft.AspNetCore.Server.Kestrel.Networking.Libuv..ctor()
   at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[TContext](IHttpApplication`1 application)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.Start()
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host, CancellationToken token, String shutdownMessage)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
   at MyApp.Web.Startup.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
   at Microsoft.Dnx.ApplicationHost.Program.<>c__DisplayClass3_0.<ExecuteMain>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Microsoft.AspNetCore.Server.Kestrel.Networking.PlatformApis..cctor()

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

我尝试手动添加依赖项,但它没有解决问题:

"System.Runtime.InteropServices.RuntimeInformation": "4.0.0-rc2-23826"

这是我的配置

global.json:

{
  "projects": [ "src", "test", "lib" ],
  "sdk": {
    "version": "1.0.0-rc2-20221",
    "runtime": "clr",
    "architecture": "x86"
  }
}

project.json

  "compilationOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "Jil": "2.13.0",
    "JWT": "1.3.4",
    "Microsoft.AspNetCore.Authentication": "1.0.0-rc2-20270",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-20270",
    "Microsoft.AspNetCore.Hosting": "1.0.0-rc2-20270",
    "Microsoft.AspNetCore.Http.Abstractions": "1.0.0-rc2-20270",
    "Microsoft.AspNetCore.IISPlatformHandler": "1.0.0-rc2-20270",
    "Microsoft.AspNetCore.Mvc.Core": "1.0.0-rc2-20270",
    "Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.0-rc2-20270",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-20270",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-20270",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-20270",
    "Microsoft.Extensions.DependencyInjection": "1.0.0-rc2-20270",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-20270",
    "Microsoft.Extensions.PlatformAbstractions.Dnx": "1.0.0-rc2-20221",
    "System.Runtime.InteropServices.RuntimeInformation": "4.0.0-rc2-23826"
  },
  "frameworks": {
    "net46": { }
  }

我已经花了一个多星期的时间尝试发布到azure并解决了这个问题,任何帮助都会非常感激。

1 个答案:

答案 0 :(得分:2)

在IIS上本地测试

Azure使用IIS。如果应用程序在IIS中运行,它通常可以在Azure Web App中运行。官方文档有clear instructions for publishing to IIS。一旦它在IIS中工作,将相同的东西部署到Azure。

RC2 Azure Publish Walk-thru

以下是适用于我的确切发布步骤。我制作了一个使用您问题中的project.json和pushed the sample to GitHub的示例。

克隆样本:

C:\> git clone https://github.com/bigfont/StackOverflow.git
C:\> cd .\StackOverflow\RuntimeInfo

然后发布项目:

C:\StackOverflow\RuntimeInfo> dnvm use 1.0.0-rc2-20221 -runtime clr
C:\StackOverflow\RuntimeInfo> dotnet restore
C:\StackOverflow\RuntimeInfo> dotnet publish -c Release -o ./approot

这些命令以RC2运行时为目标,还原NuGet包,并将发布配置发布到approot目录。这是结果:

C:\StackOverflow\RuntimeInfo> dir
approot            
bin                
obj                            
Program.cs         
project.json       
project.lock.json     
wwwroot

现在,使用FTP,将approotwwwroot目录发布到Azure的site目录。

./site
    approot
    wwwroot

这是Azure的结果。

Use of the System.Runtime.InteropServices in Azure

最后的注释

小心&#34;穿越溪流。&#34;您的app在其project.json / global.json文件中有两个发布版本:1.0.0-rc2-20221和1.0.0-rc2-20270。选择一个可能更好。