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

查看:16
本文介绍了如何在 .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"
    }
  }
}

使用 this answer 到类似的查询,我能够添加对 System.Data 的引用.常见的变化

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 工具的普通控制台中玩.有没有办法在不安装 IDE 的情况下管理 .NET Core 项目的项目依赖项?

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?

推荐答案

like poke 已经在评论中注释是正确的.为 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 包)并且只指定一个星号 "*"(你永远不应该这样做,它允许破坏更改)恢复最高可用版本.由于没有稳定,star 将找不到任何东西(后面的破折号有一些魔法).该库的 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天全站免登陆