我正在尝试创建将连接到 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
最佳答案
我可以通过 Xamarin PCL 的一些变通方法解决这个问题:
- 将您的 PCL 目标更改为 .NetStandard。您可以在 PCL 项目属性中执行此操作。
- 创建一个新的 .NetStandard ClassLibrary 项目。
- 添加 System.Data.SqlClient 和您的代码
- 将 ClassLibrary 项目 dll 引用到 PCL 项目
- 有了这个库,您就可以使用 SqlClient。
在您使用 asp.net 的情况下:也许,您可以尝试创建一个 .NetFramework ClassLibrary 并按照上述步骤操作。
希望对您有所帮助!
关于c# - 无法安装 System.Data.SqlClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41256144/