面向完整 dotnet 框架的 ASP.NET Core Web 应用程序是否在 IIS 中工作? [英] Does ASP.NET Core web application targeting full dotnet framework work in IIS?

查看:28
本文介绍了面向完整 dotnet 框架的 ASP.NET Core Web 应用程序是否在 IIS 中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将基于完整框架 (4.6.1) 开发的 ASP.NET Core 应用程序发布到 IIS.现在,代码只是使用 Visual StudioASP.NET Core (.NET Framework) 选项创建的基本模板代码.代码编译良好,但是当我将其发布到本地 IIS 时,它无法启动.我收到类似

I am trying to publish an ASP.NET Core application developed on top of full framework (4.6.1) to IIS. Right now the code is just the base template code created using the Visual Studio "ASP.NET Core (.NET Framework) option. The code compiles fine but when I publish it to Local IIS, it fails to start. I get error like

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 看起来像这样

My project.json looks like this

    {
  "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 有什么变化吗?

The same application if targeted towards dotnetcore instead of dotnet461 works fine. All MS documentation seems to say that this scenario is possible and is supported. Has something changed in 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 中的复选框以删除目的地的文件并没有解决问题,并就此打开了一个问题.

If you published the same application targeting netcoreapp1.0 first and then you the net4x version then I think it is a bug in Web Deploy. I hit a similar problem when publishing to 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). I think Web Deploy leaves some dlls behind or does not update if the names are the same and they are then picked up but fail because they are not matching the target framework and their dependencies are missing. I also found that checking the checkbox in Web Deploy to delete files at the destination did not fix the problem and opened an issue on that.

这篇关于面向完整 dotnet 框架的 ASP.NET Core Web 应用程序是否在 IIS 中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆