为什么加入我的Web API的依赖(ASP.NET V5)项目没有完全工作? [英] Why does adding a dependency in my Web API (ASP.NET v5) project not work fully?

查看:215
本文介绍了为什么加入我的Web API的依赖(ASP.NET V5)项目没有完全工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Visual Studio 2015年CTP 6在Windows 8.1。

I'm using Visual Studio 2015 CTP 6 on Windows 8.1.

我想写使用ASP.NET V5一个Web API,其新项目的文件格式。我添加了一个参考野田V1.3.0的时间到我的 project.json 文件,并在Visual Studio中的编辑把它捡起,但构建过程失败。

I'm trying to write a Web API using ASP.NET v5, with its new project file format. I've added a reference to Noda Time v1.3.0 to my project.json file, and the editor in Visual Studio picks it up, but the build process fails.

摄制配方,右从无到有:

Repro recipe, right from scratch:


  • 开启2015年VS CTP 6

  • 创建一个新的解决方案的新项目:

    • 选择ASP.NET Web应用程序项目模板

    • 在模板对话框中选择ASP.NET 5 preVIEW的Web API

    打开 project.json ,和(格式错误)依赖关系一节中,在开始添加一个额外的行(以避免加逗号另一条线路):

    Open project.json, and in the (badly formatted) "dependencies" section, add an extra line at the start (to avoid having to add a comma to another line):

    "NodaTime": "1.3.0",
    


  • 开启控制器\\ Values​​Controller.cs

  • 编辑参数的的get()方法使人体是:

    return DateTimeZoneProviders.Tzdb.Ids;
    


    • DateTimeZoneProviders 将有红色的波浪线,这是合理的 - 我们没有一个使用指令尚未

      • DateTimeZoneProviders will have red squiggles, which is reasonable - we don't have a using directive yet.
      • 在资源管理器中,如果在 BugDemo 解决方案目录看,你会发现一个文物\\ OBJ \\ BugDemo \\调试\\ ProjectRawReferences 包含目录ASP.NET 5.0的核心和ASP.NET 5.0的目录,这两者有很大的DLL的......但野田没有时间。

        In Explorer, if you look in the BugDemo solution directory, you'll find an artifacts\obj\BugDemo\Debug\ProjectRawReferences directory containing "ASP.NET Core 5.0" and "ASP.NET 5.0" directories, both of which have a lot of DLLs in... but not Noda Time.

        右键单击并选择还原包,不解决这个问题。

        Right-clicking on the project and selecting "Restore packages" doesn't fix this.

        在我建立使用Project K,一个 KPM恢复确实的回暖野田佳彦时,如果部分添加到<同一项目code> project.json 如下,那么 K网页工作与来访的 HTTP://本地主机:5001 / API /值会告诉你所有的时间TZDB区ID:

        When I build the same project using Project K, a kpm restore does pick up Noda Time, and if you add a section to project.json as below, then k web works and visiting http://localhost:5001/api/values will show you all the TZDB time zone IDs:

        "commands": {
          "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5001"
        },
        

        那么,我究竟做错了什么?或者是它只是一个错误吗?

        So, what am I doing wrong? Or is it just a bug?

        推荐答案

        当你构建,检查出的项目列 - 它指出,发生故障的版本是ASP.NET 5.0的核心(而不是ASP。 NET 5.0)。在code编辑器的左上角下拉菜单中,您可以选择不同的观点 - 如果你选择ASP.NET 5.0核心之一,你会看到NodaTime命名空间是不确定的。

        When you build, check out the "Project" column - it notes that the build that is failing is "ASP.NET Core 5.0" (not "ASP.NET 5.0"). In the upper left dropdown of the code editor, you can choose different views - if you select the "ASP.NET Core 5.0" one, you'll see that the NodaTime namespace is undefined.

        它看起来像新的ASP.NET项目模板创建多靶点的应用程序,无论是aspnet50和aspnetcore50。

        It looks like the new ASP.NET project templates are creating multi-targeted apps, both aspnet50 and aspnetcore50.

        ASP.NET 5.0是(目前)基于.NET 4.5.x,所以NodaTime便携式(NET4)满足该平台。 ASP.NET 5.0的核心是基于新的CoreClr(aspnetcore50),并且有在NodaTime库中没有二进制文件支持它。

        ASP.NET 5.0 is (currently) based on .NET 4.5.x, so the NodaTime portable (net4) satisfies that platform. ASP.NET Core 5.0 is based on the new CoreClr (aspnetcore50), and there's no binaries in the NodaTime library that support it.

        要解决,你可以仅仅通过在框架中删除的project.jsonaspnetcore50条目放弃对CoreClr支持您的应用程序

        To resolve, you can just drop support for CoreClr in your application by removing the "aspnetcore50" entry in project.json under "frameworks":

        "frameworks": {
            "aspnet50": { }
            //"aspnetcore50": { }
        },
        

        现在您的应用程序应该建立目标只是ASP.NET 5.0,而不是CoreClr。

        Now your app should build just targeting ASP.NET 5.0 and not the CoreClr.

        这篇关于为什么加入我的Web API的依赖(ASP.NET V5)项目没有完全工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆