Windows 上编译 corefx 源码生成 Linux 上可用的 System.Data.Sq
最近在排查一个奇怪的 EF Core 查询速度慢的问题,需要在 corefx 2.2.3 的?System.Data.SqlClient 源码中打点。 github 上签出 corefx 的源代码,运行 build.cmd 命令,然后用 VS2017 打开?System.Data.SqlClient.sln ,添加 Console.WriteLine?打点代码,用 VS 进行 build 。 build 之后 corefx 根路径下?binWindows_NT.AnyCPU.DebugSystem.Data.SqlClientnetstandard?文件夹中会生成 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 help 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) 而 binAnyOS.AnyCPU.Debug 中没有生成?System.Data.SqlClient.dll 。 改用 build-managed.cmd 命令 build : build-managed.cmd -Project=srcSystem.Data.SqlClientsrc 出现下面的错误提示 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 文件夹中。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- MDT2013批量升级Win7客户端至Win10
- windows – 在单个VPS上运行两个单独的Web服务器
- 铁威马NAS系统的快速安装方式
- windows-phone-8 – 项目需要先部署才能启动
- Windows命令行字符串解析:字符串中的文件夹和文件名
- .net – 在Windows XP上开发Windows Phone 7
- Microsoft AlwaysOn故障转移解决方案和Delphi
- 3dsmax2015卸载/安装失败/如何彻底卸载清除干净3dsmax2015注
- 怎么把电脑桌面上的CAD图纸转换成BMP格式图纸?
- lisp – 试试Windows中“The Little Schemer”一书中的例子