无法用'dnx web'启动Kestrel,说“当前运行时目标框架不兼容”

时间:2016-07-19 09:32:52

标签: asp.net asp.net-core dnx coreclr kestrel-http-server

关于SO有很多类似的问题,但我无法找到问题的解决方案。很明显我对.NET Core还不够熟悉......)

我有一个严格的ASP.NET核心应用程序,我正在尝试使用 dnx web 命令启动 Kestrel Web服务器,但它失败了,因为它似乎活动框架目标是 dnx451 (而不是 dnxcore50 )。

我的 global.json 如下所示:

 {
   "projects": [ "FolderName", "src", "test" ], // What IS the actual project name?

  "sdk": {
    "version": "1.0.0-rc1-update2",
    "runtime":  "coreclr", 
    "architecture": "x86"
  }
}

摘自 project.json

    "commands": {
        "web": "Microsoft.AspNet.Server.Kestrel --server.urls=http://*:8000/"
    },

  "frameworks": {
    "dnxcore50": { }
  }

最后,在 launchSettings.json

{
  "profiles": {
    "web": {
      "commandName": "web",
      "launchBrowser": false,
      "launchUrl": "http://localhost:8000",
      "environmentVariables": {
        "Hosting:Environment": "Development"
      },
      "sdkVersion": "dnx-coreclr-win-x86.1.0.0-rc1-update2"
    }
  }
}

据我所知, project.json 中的依赖项与SDK版本匹配:

"dependencies": {
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "Microsoft.ApplicationInsights.AspNet": "1.0.0-rc1",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final"
  }

然而,当我运行 dnx web 时,我得到以下内容:

System.InvalidOperationException: The current runtime target framework is not compatible with 'Okaymaker.Web'.
Current runtime target framework: 'DNX,Version=v4.5.1 (dnx451)'
 Version:      1.0.0-rc1-16609
 Type:         Clr
 Architecture: x86
 OS Name:      Windows
 OS Version:   10.0
 Runtime Id:   win10-x86

Please make sure the runtime matches a framework specified in project.json

不确定为什么它说目前的目标框架 dnx451 ?我想我可以在运行 dnx web 之前运行 dnx use ,但我觉得配置应该为我处理设置?

如果我运行 dnvm list

,这就是我看到的内容
Active Version           Runtime Architecture Location                         Alias
------ -------           ------- ------------ --------                         -----
       1.0.0-beta8       clr     x64          C:\Users\TedNyberg\.dnx\runtimes
       1.0.0-beta8       clr     x86          C:\Users\TedNyberg\.dnx\runtimes
       1.0.0-beta8       coreclr x64          C:\Users\TedNyberg\.dnx\runtimes
       1.0.0-beta8       coreclr x86          C:\Users\TedNyberg\.dnx\runtimes
       1.0.0-rc1-update1 clr     x64          C:\Users\TedNyberg\.dnx\runtimes
       1.0.0-rc1-update1 clr     x86          C:\Users\TedNyberg\.dnx\runtimes
       1.0.0-rc1-update1 coreclr x64          C:\Users\TedNyberg\.dnx\runtimes
       1.0.0-rc1-update1 coreclr x86          C:\Users\TedNyberg\.dnx\runtimes
  *    1.0.0-rc1-update2 clr     x86          C:\Users\TedNyberg\.dnx\runtimes default
       1.0.0-rc1-update2 coreclr x86          C:\Users\TedNyberg\.dnx\runtimes

修改:通过安装 Visual Studio 2015 Update 3 更新的工具,似乎可以解决/避免这些问题。 NET Core ,均可在以下网址获得:https://www.microsoft.com/net/core#windows

1 个答案:

答案 0 :(得分:0)

您必须使用dnvm use将当前运行时设置为coreclr。 VisualStudio不够智能,但已发布的脚本足够智能,可以构建一个shell脚本来静态选择正确的引擎。

这是RC1的一个确认的设计缺陷(很抱歉懒得从ASP.NET社区Standup中搜索视频笔记)并在dotnet命令行界面中得到修复。