我正在尝试创建将连接到SQL Server并运行存储过程的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的一些解决方法来解决此问题:
将您的PCL目标更改为.NetStandard。您可以在PCL项目属性中执行此操作。
创建一个新的.NetStandard ClassLibrary项目。
添加System.Data.SqlClient和您的代码
将ClassLibrary项目dll引用到PCL项目
使用此库,您可以使用SqlClient。
对于使用asp.net的情况:也许,您可以尝试创建.NetFramework ClassLibrary并按照上述步骤操作。
希望对您有帮助!