在Asp.Net 5起订量使用与dnx50 [英] using Moq in Asp.Net 5 with dnx50

查看:111
本文介绍了在Asp.Net 5起订量使用与dnx50的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的起订量,并有一个问题,当我用它在我的Asp.Net 5和6 MVC测试项目。

I am new to moq and have a problem when I use it in my test project with Asp.Net 5 and MVC 6.

我装起订量使用的NuGet并安装起订量4.2.1510.2205。当我检查project.json,我得到了

I installed Moq by using NuGet and installed Moq 4.2.1510.2205. When I checked project.json, I got

{
  "version": "1.0.0-*",
  "description": "TargetTests Class Library",
  "authors": [ "Admin" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",

  "dependencies": {
    "Target": "1.0.0-*",
    "xunit": "2.2.0-beta1-build3239",
    "xunit.runner.console": "2.2.0-beta1-build3239",
    "xunit.runner.dnx": "2.1.0-rc1-build204"
  },

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

  "frameworks": {
    "dnx451": {
      "dependencies": {
        "Moq": "4.2.1510.2205"
      }
    },
    "dnxcore50": {
      "dependencies": {
      }
    }
  }
}

当我加入一个CS文件中使用起订量,我得到了以下错误

When I add using Moq in a cs file, I got the following error

Severity    Code    Description Project File    Line    Suppression State
Error   CS0246  The type or namespace name 'Moq' could not be found (are you missing a using directive or an assembly reference?)   TargetTests.DNX Core 5.0    C:\Users\Admin\Desktop\Target\src\TargetTests\TestBase.cs   6   Active

谁能帮忙看看怎么解决这个问题呢?我已签StackOverfollow并试图在介绍的方法进行嘲弄框架asp.net核心5.0 ,但失败了。

推荐答案

这是因为你是从的NuGet安装起订量版本不支持DNX平台,您的项目配置凭借具有的是该平台上可运行dnxcore50组件在project.json文件。

This is because the Moq version you have installed from NuGet does not support DNX platform, and your project is configured to be runnable on that platform by virtue of having a "dnxcore50" component in your project.json file.

如果您将光标悬停的方法调用起订量,你应该看到这样的事情:

If you hover your cursor over a method call to Moq, you should see something like this:

要解决这个问题,你有两个选择:

To fix this, you have two options:


  1. 删除dnxcore50从project.json文件组件。 (您code只有只会与ASP.Net enviornments功能4.5.1+安装为一个结果。)

  2. 添加版起订量,支持ASP.Net核心/ DNX框架。

  1. Remove the "dnxcore50" component from your project.json file. (Your code only will only function in enviornments with ASP.Net 4.5.1+ installed as a result.)
  2. Add a version of Moq that supports the ASP.Net Core/DNX Framework.

如果您想要做的选择后者,href=\"http://stackoverflow.com/a/34933925/4270650\">当我尝试过了卢卡斯Pyrzyk 第二个答案工作的

If you'd like to do the latter option, the second answer by Lucas Pyrzyk worked when I tried it out (including the comment below his answer).

首先,添加一个依赖你project.json到 moq.netcore 库。

First, add a dependency to your project.json to the moq.netcore library.

{
  "version": "1.0.0-*",
    "description": "TargetTests Class Library",
    "authors": [ "Admin" ],
    "tags": [ "" ],
    "projectUrl": "",
    "licenseUrl": "",

    "dependencies": {
      "Target": "1.0.0-*",
      "xunit": "2.2.0-beta1-build3239",
      "xunit.runner.console": "2.2.0-beta1-build3239",
      "xunit.runner.dnx": "2.1.0-rc1-build204"
    },

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

    "frameworks": {
      "dnx451": {
        "dependencies": {
          "Moq": "4.2.1510.2205"
        }
      },
      "dnxcore50": {
        "dependencies": {
          "moq.netcore": "4.4.0-beta8"
        }
      }
    }

然后,在你的项目的根正在使用它添加一个名为 NuGet.config 文件。它的内容应该是这样的:

Then, add a file called NuGet.config in the root of your project that is using it. It's contents should look like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="AspNetVNext" value="https://www.myget.org/F/aspnet-contrib/api/v3/index.json" />
    <add key="NuGet" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

这篇关于在Asp.Net 5起订量使用与dnx50的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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