Dapper和MVC VNext中的问题

Mig*_*ura 6 dapper asp.net-core-mvc

我为ASP.NET MVC VNext项目的测试创建了一个类库.

在这个类库中,我使用的是Dapper,所以我有了project.json:

{

  "dependencies": {
    "xunit": "2.1.0-beta2-*",
    "xunit.runner.dnx": "2.1.0-beta2-*",
    "Dapper": "1.42.0"
  },

  "commands": {
    "test": "xunit.runner.dnx"
  },

  "frameworks": {

    "dnx451": {
      "dependencies": {
        "Dapper": "1.42.0"
      }
    },

    "dnxcore50": {
      "dependencies": {
        "System.Collections": "4.0.10-beta-22816",
        "System.Linq": "4.0.0-beta-22816",
        "Microsoft.CSharp": "4.0.0-beta-22816",
        "Dapper": "1.42.0"
      }
    }

  }
}
Run Code Online (Sandbox Code Playgroud)

我一直收到错误:

The type or namespace name 'Dapper' could not be found (are you missing a using directive or an assembly reference?)    MvcProj.Test.DNX Core 5.0   
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

Mat*_*att 9

使用Dapper的测试版

由于dnxcore50仍然处于测试阶段,Dapper的发布版本都没有声明它的发布支持.这就是为什么Dapper家伙没有把它放在发布包中.

Dapper的beta版本中提供了 DNX beta支持.尝试使用版本1.41.0-beta5,或其nuget Feed中的最新非发行版本.

"dependencies": {
    //...
    "System.Data.SqlClient": "4.0.0-beta-23225",
    "Dapper": "1.41.0-beta5"
},
Run Code Online (Sandbox Code Playgroud)

我现在正在我的应用程序中使用它,它似乎运行良好.


N. *_*len 5

您看到的问题是由于Dapper没有为dnxcore50(CoreCLR)构建一个包.有3种方法可以解决这个问题.

  1. "dnxcore50"从您的节点中删除节点project.json(这意味着您将不再构建节点dnxcore50).
  2. 在您的应用程序代码中,您正在使用Dapperifdefs:#if DNX451.... 来包围这些代码片段#endif.这然后进行你的应用程序只使用Dapperdnx451构建配置.
  3. 转换Dapper为构建dnxcore50.这需要获取源代码并进行必要的更改dnxcore50.