ASP.NET 以完整的 dotnet 框架为目标的核心 Web 应用程序是否可以在 IIS 中运行?
Does ASP.NET Core web application targeting full dotnet framework work in IIS?
我正在尝试将在完整框架 (4.6.1) 之上开发的 ASP.NET 核心应用程序发布到 IIS。现在代码只是使用 Visual Studio "ASP.NET Core (.NET Framework) 选项创建的基本模板代码。代码编译正常,但是当我将它发布到本地 IIS 时,它无法启动。我收到类似
的错误
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.Reflection.TypeExtensions, 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.GetEntryAssembly()
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()
我的project.json看起来像这样
{
"dependencies": {
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"net461": { }
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
相同的应用程序如果针对 dotnetcore 而不是 dotnet461 工作正常。所有 MS 文档似乎都说这种情况是可能的并且受到支持。 RTM 有什么变化吗?
如果您首先发布了针对 netcoreapp1.0
的同一应用程序,然后发布了 net4x
版本,那么我认为这是 Web 部署中的错误。我在发布到 Azure 时遇到了类似的问题 - https://github.com/aspnet/Hosting/issues/801#issuecomment-227920473. I fixed it by first manually deleting all the contents in the target folder and then publishing the application targeting net4x
again (https://github.com/aspnet/Hosting/issues/801#issuecomment-228123238)。我认为 Web Deploy 会留下一些 dll,或者如果名称相同则不会更新,然后将它们拾取但失败,因为它们与目标框架不匹配并且缺少它们的依赖项。我还发现选中 Web Deploy 中的复选框以删除目标位置的文件并没有解决问题,并为此打开了一个问题。
我正在尝试将在完整框架 (4.6.1) 之上开发的 ASP.NET 核心应用程序发布到 IIS。现在代码只是使用 Visual Studio "ASP.NET Core (.NET Framework) 选项创建的基本模板代码。代码编译正常,但是当我将它发布到本地 IIS 时,它无法启动。我收到类似
的错误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.Reflection.TypeExtensions, 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.GetEntryAssembly()
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()
我的project.json看起来像这样
{
"dependencies": {
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"net461": { }
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
相同的应用程序如果针对 dotnetcore 而不是 dotnet461 工作正常。所有 MS 文档似乎都说这种情况是可能的并且受到支持。 RTM 有什么变化吗?
如果您首先发布了针对 netcoreapp1.0
的同一应用程序,然后发布了 net4x
版本,那么我认为这是 Web 部署中的错误。我在发布到 Azure 时遇到了类似的问题 - https://github.com/aspnet/Hosting/issues/801#issuecomment-227920473. I fixed it by first manually deleting all the contents in the target folder and then publishing the application targeting net4x
again (https://github.com/aspnet/Hosting/issues/801#issuecomment-228123238)。我认为 Web Deploy 会留下一些 dll,或者如果名称相同则不会更新,然后将它们拾取但失败,因为它们与目标框架不匹配并且缺少它们的依赖项。我还发现选中 Web Deploy 中的复选框以删除目标位置的文件并没有解决问题,并为此打开了一个问题。