【发布时间】:2016-11-09 07:20:45
【问题描述】:
我正在尝试将在完整框架 (4.6.1) 之上开发的 ASP.NET Core 应用程序发布到 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 有什么变化吗?
【问题讨论】:
-
是的,应该而且确实如此(我检查过)。在这种情况下我总是做的第一件事是: 1. 检查它是否从源目录中的命令行运行,
dotnet run2. 检查我是否从已发布的 IIS 网站根目录中的命令行运行(应该有一个可执行文件,如 @ 987654324@ 3. 从%userprofile%/.nuget中删除所有内容,再次运行dotnet restore,从IIS 网站根目录中删除所有内容,然后再次运行dotnet publish。 -
@qbik 您的步骤 3 和下面的 pawel 问题的组合似乎解决了我的问题。谢谢。
标签: asp.net asp.net-core .net-core asp.net-core-1.0