加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

Windows 上编译 corefx 源码生成 Linux 上可用的 System.Data.Sq

发布时间:2020-12-14 02:17:22 所属栏目:Windows 来源:网络整理
导读:最近在排查一个奇怪的 EF Core 查询速度慢的问题,需要在 corefx 2.2.3 的?System.Data.SqlClient 源码中打点。 github 上签出 corefx 的源代码,运行 build.cmd 命令,然后用 VS2017 打开?System.Data.SqlClient.sln ,添加 Console.WriteLine?打点代码,用

最近在排查一个奇怪的 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 文件夹中。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读