System.Runtime问题将ASP.NET Core RC2应用程序发布到IIS

时间:2016-05-30 04:16:16

标签: asp.net-core

我正在尝试将ASP.NET Core RC2应用程序发布到IIS。我正在使用以下命令创建包:

dotnet publish -f net451 -r win10-x64 -o C:\pub

当我尝试在IIS中运行应用程序时,我在日志文件中收到以下错误:

Unhandled Exception: System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation. ---> 
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime,
Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
The system cannot find the file specified.
at IoC.DepedencyConfiguration.AddMyAppServices(IServiceCollection services, IConfigurationRoot configuration)
at MyApp.Web.Startup.ConfigureServices(IServiceCollection services) in C:\git\MyApp\src\Web\Startup.cs:line 52
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.Startup.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection exportServices)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at MyApp.Web.Program.Main(String[] args) in C:\git\MyApp\src\Web\Program.cs:line 14

如果我尝试在命令行中运行可执行文件,则会发生同样的错误。

但是,如果我直接在其代码文件夹中使用以下命令运行App:

dotnet run -f 451

一切都运行良好。我也尝试将框架切换到net46,但我有相同的行为。我也试过引用"System.Runtime": "4.1.0-rc2-*",也没有帮助。

这是我的project.json:

{
  "version": "1.0.0-*",
  "userSecretsId": "aspnet5-MyApp-00000000-0000-0000-0000-000000000000",

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "gcServer": true
  },

  "tools": {
    "Microsoft.EntityFrameworkCore.Tools": {
      "imports": ["portable-net451+win8"],
      "version": "1.0.0-preview1-final"
    }
  },

  "dependencies": {
    "Data.CrossCutting.Identity": "1.0.0-*",
    "IoC": "1.0.0-*",
    "Services.Contracts": "1.0.0-*",
    "Services.HangFire": "1.0.0-*",
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Authentication.Facebook": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Authentication.Google": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc.WebApiCompatShim": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Owin": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Hosting.Abstractions": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Razor": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0-rc2-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dnxcore50",
        "dotnet5.6",
        "portable-net45+win8"
      ],
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.0.0-rc2-3002702",
          "type": "platform"
        }
      }
    },
    "net451": {
      "dependencies": {
        "Hangfire": "1.5.3"
      }
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "web.config",
      "appsettings.json",
      "appsettings.*.json"
    ]

  }

}

1 个答案:

答案 0 :(得分:0)

对不起这个问题,通过添加到project.json,我能够在更多文档阅读之后修复它:

"tools": {
  "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
    "version": "1.0.0-preview1-final",
    "imports": "portable-net45+wp80+win8+wpa81+dnxcore50"
   }
},
"scripts": {
  "postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
}