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

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

问题描述

我正在尝试将在完整框架(4.6.1)之上开发的ASP.NET Core应用程序发布到IIS。现在,该代码只是使用Visual Studio ASP.NET Core(.NET Framework)选项创建的基本模板代码。该代码可以很好地编译,但是当我将其发布到Local IIS时,它无法启动。 / p>

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天全站免登陆