2016-10-01 104 views
0

ASP.NET Core项目是否可以针对net461并在Azure网站上运行?Azure中针对net461的ASP.NET核心版


这是什么已经尝试和失败。

定位时netcoreapp1.0但是当我将其更改为net461(包括一些其他必要的改动就可以编译)我收到以下错误它的工作原理:

Unhandled Exception: System.TypeInitializationException: The type initializer for 'Microsoft.Extensions.PlatformAbstractions.PlatformServices' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. 
    at Microsoft.Extensions.PlatformAbstractions.ApplicationEnvironment.GetApplicationBasePath() 
    at Microsoft.Extensions.PlatformAbstractions.ApplicationEnvironment..ctor() 
    at Microsoft.Extensions.PlatformAbstractions.PlatformServices..ctor() 
    at Microsoft.Extensions.PlatformAbstractions.PlatformServices..cctor() 
    --- End of inner exception stack trace --- 
    at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildHostingServices() 
    at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build() 
    at WebApplication1.Program.Main(String[] args) in C:\Users\a\WebApplication1\Program.cs:line 14 

具体

System.IO.FileNotFoundException: Could not load file or assembly 'System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

当地正常工作。

我天真地添加了nuget包来包含所需的程序集。

{ 
    "dependencies": { 
    "Microsoft.AspNetCore.Diagnostics": "1.0.0", 
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", 
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", 
    "Microsoft.AspNetCore.StaticFiles": "1.0.0", 
    "Microsoft.Extensions.Logging.Console": "1.0.0", 
    "Newtonsoft.Json": "9.0.1", 
    "System.AppContext": "4.1.0", 
    "System.Reflection.TypeExtensions": "4.1.0", 
    "System.Security.Cryptography.X509Certificates": "4.1.0" 
    }, 

最终我得到了一个别样的错误:

warn: Microsoft.AspNetCore.Server.Kestrel[0] 
     Unable to bind to http://localhost:7762 on the IPv6 loopback interface. 
System.AggregateException: One or more errors occurred. ---> Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -4089 EAFNOSUPPORT address family not supported 
    at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.Check(Int32 statusCode) 
    at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.tcp_bind(UvTcpHandle handle, SockAddr& addr, Int32 flags) 
    at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.Bind(ServerAddress address) 
    at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListener.CreateListenSocket() 
    at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.<>c.<StartAsync>b__6_0(Object state) 
    --- End of inner exception stack trace --- 

我不知道在哪里可以从这里走。

回答

2

虽然发布配置文件有选项选中“删除目标位置上的其他文件”,但仍然有一些文件已保留。

使用FTP并在发布之前手动删除所有文件解决了项目。

ASP.NET核心目标net461适用于Azure,前提是您尚未在其中发布任何其他框架。

我在问题中添加的这些NuGet包也不需要,可以安全地从项目中删除。

"System.AppContext": "4.1.0", 
"System.Reflection.TypeExtensions": "4.1.0", 
"System.Security.Cryptography.X509Certificates": "4.1.0" 
+2

顺便说一句,你还可以使用[捻控制台(https://github.com/projectkudu/kudu/wiki/Kudu-console),这比FTP,查看更加方便/管理文件。 –