如何在.NET Core RC2控制台应用程序(Linux,Debian 8)中使用System.Data? [英] How do I use System.Data in a .NET Core RC2 console app (Linux, Debian 8)?

查看:155
本文介绍了如何在.NET Core RC2控制台应用程序(Linux,Debian 8)中使用System.Data?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Debian 8 amd64系统上安装了.NET Core RC2,并希望测试是否可以查询Microsoft SQL Server实例.

I've installed .NET Core RC2 on a Debian 8 amd64 system and would like to test if it's possible to query an instance of Microsoft SQL Server.

所以我想在项目中添加对System.Data.SqlClient程序集的依赖.

So I'd like to add to my project a dependency on the System.Data.SqlClient assembly.

目前,通过运行dotnet new CLI工具创建的我的项目文件如下所示:

Presently my project file created by running the dotnet new CLI tool looks like this:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0-rc2-3002702"
    }
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"
    }
  }
}

对于类似的查询,使用此答案,我能够添加对System.Data.Common更改的引用>

Using this answer to a similar query, I was able to add a reference to System.Data.Common changing the

"frameworks": {
  "netcoreapp1.0": {
    "imports": "dnxcore50"
  }
}

片段到

"frameworks": {
  "netcoreapp1.0": {
    "imports": "dnxcore50",
    "dependencies": {
      "System.Data.Common": "*"
    }
  }
}

这使得dotnet restore使用NuGet下载一堆东西.

which made dotnet restore use NuGet to download a bunch of stuff.

然后我尝试将该片段更改为要读取

I then tried to change that fragment to read

"frameworks": {
  "netcoreapp1.0": {
    "imports": "dnxcore50",
    "dependencies": {
      "System.Data.SqlClient": "*"
    }
  }
}

但是NuGet表示是

无法为'.NETCoreApp,Version = v1.0'解析'System.Data.SqlClient'.

Unable to resolve 'System.Data.SqlClient' for '.NETCoreApp,Version=v1.0'.

如果我将版本字符串更改为"4.1.0-rc3- *",则错误消息会变得更加具体:

If I change the version string to read "4.1.0-rc3-*" the error message just gets more specific:

无法为'.NETCoreApp,Version = v1.0'解析'System.Data.SqlClient(> = 4.1.0-rc3).

Unable to resolve 'System.Data.SqlClient (>= 4.1.0-rc3)' for '.NETCoreApp,Version=v1.0'.

让我感到困惑的是,专门用于.NET Core的NuGet软件包库明确列出System.Data.SqlClient可用.

What I'm puzzled about is that the NuGet package gallery dedicated to .NET Core explicitly lists System.Data.SqlClient as available.

那我该怎么做才能在项目中添加对System.Data.SqlClient程序集的引用并让NuGet下载呢?

So what could I do to add a reference to System.Data.SqlClient assembly to my project and have NuGet download it?

顺便说一句,我目前仅使用dotnet CLI工具在普通控制台中玩耍.是否可以通过任何方法来管理.NET Core项目的项目依赖性,而无需借助安装IDE?

On a side note, I'm currently playing around in a plain console with only the dotnet CLI tool. Is there any way to manage project dependencies for a .NET Core project without resorting to installing IDEs?

推荐答案

在注释中已注释的戳戳是正确的.将版本指定为System.Data.SqlClient使恢复愉快;)

Like poke already annotated in the comment is correct. Specify a version to System.Data.SqlClient makes your restore happy ;)

那是为什么? System.Data.SqlClient存在于 http://nuget.org 库中.在项目边界之外(例如nuget feed程序包),不允许未指定版本("),而仅指定星号"*"(您绝对不能这样做,因为它允许重大更改),以恢复可用的最高版本.由于没有稳定点,所以恒星将找不到任何东西(后面有一些破折号的魔术).提到的该库的RC2版本是4.1.0-rc2-24027,当您使用4.1.0-rc2- *进行询问时,它将使用最高的RC2版本(但只有一个).相比之下,System.Data.Common在nuget.org上具有针对通用Windows平台的公开发布,因此被发现.

Why is that? System.Data.SqlClient exists in the http://nuget.org gallery. Not specifying a version ("") is not allowed outside of the boundaries of a project (like a nuget feed package) and specifying solely an star "*" (you should never do that, it allows breaking changes) restore the highest available version. Since there is no stable, star will not find anything (there is some magic with the dashes behind). The RC2 version of that library is the mentioned 4.1.0-rc2-24027 and when you ask with 4.1.0-rc2-* it will take the highest of the RC2 builds (but there is only one). In comparison System.Data.Common has a public release on nuget.org for the Universal Windows Platform and is found for that reason.

RC3是下一版本,并且仅适用于.NET Core和ASP.NET Core团队的开发人员供稿,不适用于公共nuget供稿.你不应该和他们一起玩.

The RC3 is the next release and only available on developer feeds from the .NET Core and ASP.NET Core team and not the public nuget feed. You should not play with them.

这篇关于如何在.NET Core RC2控制台应用程序(Linux,Debian 8)中使用System.Data?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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