ASP.NET Core项目可以定位net461并在Azure网站上运行吗?
以下是经过尝试和失败的内容。
在定位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:无法加载文件或程序集' System.AppContext ,版本= 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其中一个依赖项。系统找不到指定的文件。
在当地一切正常。
我天真地添加了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 ---
我不知道从哪里开始。
答案 0 :(得分:2)
虽然发布配置文件已选中选项&#34;删除目的地的其他文件&#34;仍然有一些文件遗留下来。
使用FTP并在发布之前手动删除所有文件解决了项目。
ASP.NET核心目标net461适用于Azure,假设您之前没有发布任何其他框架。
我在问题中添加的这些NuGet包也不需要,可以安全地从项目中删除。
"System.AppContext": "4.1.0",
"System.Reflection.TypeExtensions": "4.1.0",
"System.Security.Cryptography.X509Certificates": "4.1.0"