【问题标题】:Unable to install the System.Data.SqlClient无法安装 System.Data.SqlClient
【发布时间】:2016-12-21 06:03:06
【问题描述】:

我正在尝试创建将连接到 SQL 服务器并运行存储过程的 Web API。我想将System.Data.SqlClient 安装到项目中,以便提供连接详细信息。但是当试图通过Nuget Manager 安装它时,它会抛出类似

的错误
 Install failed. Rolling back...
 Could not install package 'System.Data.SqlClient 4.3.0'.
 You are trying to install this package into a project that targets. 
 '.NETFramework,Version=v4.5', but the package does not contain any 
 assembly references or content files that are compatible with that 
 framework. For more information, contact the package author.

我该如何安装它们,或者有没有其他方法可以在web.config 中提供连接字符串

【问题讨论】:

  • 为什么不给项目添加dll?
  • 我在参考程序集中没有看到它们
  • 您使用的是哪个 nuget 版本?
  • 如何查看我们的版本
  • 在 Visual Studio 中,使用帮助 > 关于 Microsoft Visual Studio 命令并查看 NuGet 包管理器旁边显示的版本。

标签: c# asp.net asp.net-web-api nuget-package


【解决方案1】:

我可以通过 Xamarin PCL 的一些解决方法来解决这个问题:

  1. 将您的 PCL 目标更改为 .NetStandard。您可以在 PCL 项目属性中执行此操作。
  2. 创建一个新的 .NetStandard ClassLibrary 项目。
  3. 添加 System.Data.SqlClient 和您的代码
  4. 将 ClassLibrary 项目 dll 引用到 PCL 项目
  5. 有了这个库,您可以使用 SqlClient。

在您使用 asp.net 的情况下:也许,您可以尝试创建一个 .NetFramework ClassLibrary 并按照上述步骤操作。

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-26
    • 2020-10-12
    • 2023-01-30
    • 2014-01-08
    相关资源
    最近更新 更多