【问题标题】:Does ASP.NET Core web application targeting full dotnet framework work in IIS?面向完整 dotnet 框架的 ASP.NET Core Web 应用程序是否在 IIS 中工作?
【发布时间】: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 run 2. 检查我是否从已发布的 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


【解决方案1】:

如果您首先发布了针对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 中的复选框以删除目标位置的文件并没有解决问题并就此打开了一个问题。

【讨论】:

  • 非常感谢。我的问题从 azure publish 开始,然后在本地 IIS 上继续。我最初将应用程序定位在 netcoreapp1.0 上。创建了一个全新的应用程序并在本地和 azure 上发布,现在一切似乎都正常了。
  • 同样的解决方案对我有用。如果有人(比如我)不知道在哪里删除文件,这里有一个管理应用程序 https://.scm.azurewebsites.net/DebugConsole,您可以在其中删除或添加文件。
猜你喜欢
  • 2019-08-19
  • 1970-01-01
  • 2018-12-29
  • 2016-09-20
  • 1970-01-01
  • 2016-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多