加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – ASP.NET vNext对ADO.NET的引用破坏了

发布时间:2020-12-16 07:13:04 所属栏目:asp.Net 来源:网络整理
导读:我有一个简单的ASP.NET vNext类库项目,当引用System.Data中的类型时,它无法编译;我在这里做错了什么,或者vnext中有问题? 我像这样设置我的project.json: { "dependencies": { "System.Data.Common": "1.0.0-alpha3" },"frameworks": { "net451": { "depend
我有一个简单的ASP.NET vNext类库项目,当引用System.Data中的类型时,它无法编译;我在这里做错了什么,或者vnext中有问题?

我像这样设置我的project.json:

{
    "dependencies": {
        "System.Data.Common": "1.0.0-alpha3"
    },"frameworks": {
        "net451": {
            "dependencies": {
            }
        },"k10": {
            "dependencies": {
            }
        }
    }
}

在输入“System.Data.Common”引用时,nuget intellisense工作正常;保存文件后,包恢复按预期发生.

然后我添加了一个引用System.Data.IDbConnection的项目接口,如下所示:

using System.Data;

namespace MyProj.Common.Data
{
    public interface IDbConnectionFactory
    {
        IDbConnection CreateConnection();
    }
}

这个炸弹在建造时间:

Error 1 The type or namespace name ‘IDbConnection’ could not be found
(are you missing a using directive or an assembly
reference?) C:UsersAdministratorProjMyProjMyProj.CommonDataIDbConnectionFactory.cs 7 9 MyProj.Common

我的KVM列表:

C:UsersAdministratorProjMyProj [next +3 ~2 -0 !]> kvm list

Active Version            Runtime Architecture Location                             Alias
------ -------            ------- ------------ --------                             -----
  *    1.0.0-alpha3       svr50   x64          C:UsersAdministrator.krepackages default
       1.0.0-alpha3       svr50   x86          C:UsersAdministrator.krepackages
       1.0.0-alpha3       svrc50  x64          C:UsersAdministrator.krepackages
       1.0.0-alpha3       svrc50  x86          C:UsersAdministrator.krepackages
       1.0.0-alpha4-10364 CLR     amd64        C:UsersAdministrator.krepackages
       1.0.0-alpha4-10364 CLR     x86          C:UsersAdministrator.krepackages
       1.0.0-alpha4-10364 CoreCLR amd64        C:UsersAdministrator.krepackages
       1.0.0-alpha4-10364 CoreCLR x86          C:UsersAdministrator.krepackages
       1.0.0-alpha4-10365 CLR     amd64        C:UsersAdministrator.krepackages
       1.0.0-alpha4-10365 CLR     x86          C:UsersAdministrator.krepackages


C:UsersAdministratorProjMyProj [next +3 ~2 -0 !]>

Can ASP.NET vNext use non-vNext references?问题似乎非常相似,但这里的错误信息有些不同,nuget intellisense表明ADO.NET包是为K10构建的.

解决方法

IDbConnection在桌面版.NET中的System.Data.dll中定义.它不包含在System.Data.Common中,它只包含将在不同版本的运行时提供的ADO.NET类型的子集.如果您的应用程序只能对桌面.NET工作,那么您应该能够引用完整的System.Data.dll并使用它中的任何类型.如果您希望能够定位基于CoreCLR的运行时,您应该坚持使用System.Data.Common中定义的类型,例如在这种情况下,您可以使用DbConnection.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读