简体   繁体   中英

Does ASP.NET Core web application targeting full dotnet framework work in 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()

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%" ]
  }
}

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM