c# - 无法安装 System.Data.SqlClient

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

我正在尝试创建将连接到 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

中提供 connectionStrings

最佳答案

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

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

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

希望对您有所帮助!

关于c# - 无法安装 System.Data.SqlClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41256144/

相关文章:

c# - 如何在reportviewer控件中传递报表参数

c# - Response.BinaryWrite() 在模态弹出窗口中不起作用

c# - 使用 jquery 函数检查 asp.net 标签属性

asp.net-web-api - JwtBearerAuthenticationOptions 不包含 IssuerSecurityTokenProviders 的定义

c# - 选择不在 ASP.NET Core Web API Controller 中等待异步函数运行

c# - 从已编译的 DLL 中获取所有 XAML 文件

c# - 参数字典包含不可为空类型 'testId' 的参数 'System.Int32' 的空条目

c# - 如何解决 ASP.net 上的 System.Data.SqlClient.SqlException 错误?

c# - 远程托管服务器上 Web 服务的间歇性问题

azure - 将 .Net Core 3.0 Web API 部署到 Azure 应用服务时出错