大佬教程收集整理的这篇文章主要介绍了Windows 上编译 corefx 源码生成 Linux 上可用的 System.Data.SqlClient.dll,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
最近在排查一个奇怪的 EF Core 查询速度慢的问题,需要在 corefx 2.2.3 的 System.Data.sqlClient 源码中打点。
github 上签出 corefx 的源代码,运行 build.cmd 命令,然后用 VS2017 打开 System.Data.sqlClient.sln ,添加 Console.WriteLine 打点代码,用 VS 进行 build 。
build 之后 corefx 根路径下 bin\Windows_NT.Anycpu.Debug\System.Data.sqlClient\netstandard 文件夹中会生成 System.Data.sqlClient.dll 文件,但这个 dll 在 Linux 上无法使用(错误如下)。
The type initializer for ‘System.Data.sqlClient.SNILoadHandle‘ threw an exception. ---> System.DllNotFoundException: Unable to load shared library ‘sni.dll‘ or one of its dependencies. In order to @R_801_11423@p diagnose loading problems,consider setTing the LD_DEBUG environment variable: libsni.dll: cAnnot open shared object file: No such file or directory at System.Data.sqlClient.SNINativeMethodWrapper.SNIInitialize(IntPtr pmo)
而 bin\AnyOs.Anycpu.Debug 中没有生成 System.Data.sqlClient.dll 。
改用 build-managed.cmd 命令 build :
error CS1069: The type name ‘Console‘ Could not be found in the namesp ace ‘System‘. This type has been forWARDed to assembly ‘System.Console,Version=0.0.0.0,Culture=neutral,PublicKeyToke n=b03f5f7f11d50a3a‘ Consider adding a reference to that assembly.
在 System.Data.sqlClient.csproj 中添加 System.Console 的引用后消除了上面的错误提示。
<ItemGroup Condition="‘$(TargetGroup)‘ == ‘netcoreapp‘"> <Reference Include="System.Console" /> <Reference Include="System.Runtime.Extensions" /> <Reference Include="System.Data.Common" /> <Reference Include="System.ComponentModel.Primitives" /> <Reference Include="System.Xml.ReaderWriter" /> <Reference Include="System.Runtime.Interopservices" /> </ItemGroup>
但 build 结果与 Visual stuido 一样,得不到 Linux 版的 System.Data.sqlClient.dll 。
到 Linux 机器上试了试,运行 ./build-managed.sh 命令后会在 bin/AnyOs.Anycpu.Debug 文件夹中生成 System.Data.sqlClient.dll ,原来要得到 Linux 上可用的 System.Data.sqlClient.dll 需要 build 输出到 bin/AnyOs.Anycpu.Debug 文件夹。
但 Linux 上 build 有个问题,每次修改代码后 build 总会出现下面的错误:
/root/corefx/Tools/sign.targets(113,5): error : /root/corefx/bin/obj/ref/Microsoft.CSharp/4.0.0.0/netstandard/Microsoft.CSharp.dll: PE file is already strong-name signed. [/root/corefx/src/Microsoft.CSharp/ref/Microsoft.CSharp.csproj]
需要运行 ./build-managed.sh -CleanAllProjects 命令才能消除这个错误。
继续回到 Windows 上,运行 build-managed.cmd -? 命令仔细看了一下命令参数,发现了 -OSGroup 参数
[-OSGroup] Sets the OS for the BuildConfigurtation you want to build. => Default value: ${OSNamE} => Legal values: [Windows_NT,Unix,Linux,OSX,FreeBSD,NetBSD].
于是使用下面的命令进行 build
build-managed.cmd -OSGroup=Linux
这样 build 后会在 bin 中多了 Linux.Anycpu.Debug 与 Unix.Anycpu.Debug 文件夹, Linux 上可用的 System.Data.sqlClient.dll 就在 Unix.Anycpu.Debug 文件夹中。
以上是大佬教程为你收集整理的Windows 上编译 corefx 源码生成 Linux 上可用的 System.Data.SqlClient.dll全部内容,希望文章能够帮你解决Windows 上编译 corefx 源码生成 Linux 上可用的 System.Data.SqlClient.dll所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。