我正在尝试将在完整框架(4.6.1)之上开发的ASP.NET Core应用程序发布到IIS。现在,该代码只是使用Visual Studio“ ASP.NET Core(.NET Framework)选项创建的基本模板代码。代码可以很好地编译,但是当我将其发布到Local 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 Deploy中的错误。发布到Azure时遇到了类似的问题-https: //github.com/aspnet/Hosting/issues/801#issuecomment-227920473。我通过首先手动删除目标文件夹中的所有内容,然后net4x
再次发布定位目标的应用程序来修复了该问题(https://github.com/aspnet/Hosting/issues/801#issuecomment-228123238)。我认为,如果名称相同,Web Deploy会留下一些dll或不更新,然后将其拾取,但由于它们与目标框架不匹配且其依赖项缺失而失败。我还发现,选中Web Deploy中的复选框以删除目标位置的文件并不能解决问题,并因此打开了一个问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句