针对完整dotnet框架的ASP.NET Core Web应用程序是否可以在IIS中运行?

时间:2016-07-07 04:32:18

标签: asp.net asp.net-core .net-core asp.net-core-1.0

我正在尝试将基于完整框架(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 个答案:

答案 0 :(得分:8)

如果您首先发布了针对netcoreapp1.0的同一应用程序,然后发布了net4x版本,那么我认为这是Web部署中的一个错误。我在发布到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中的复选框以删除目标位置的文件并没有解决问题,并在此处打开了一个问题。