简体   繁体   English

如何分发32位和64位版本的库

[英]How to distribute both 32 and 64 bit versions of the library

I have a C# library that is called by various clients (both 32-bit and 64-bit). 我有一个C#库,由各种客户端(32位和64位)调用。 Up to now it was compiled as AnyCPU, so there was no issues. 到目前为止它被编译为AnyCPU,所以没有问题。

Recently I added a dependency to SQLite .NET library which come in both 32 and 64-bit flavors (but not AnyCPU). 最近我添加了一个依赖于SQLite .NET库,它有32位和64位版本(但不是AnyCPU)。 So, now, I have to have 2 builds - for both bitnesses. 所以,现在,我必须有两个版本 - 两个比特。

In the past, I've seen other libraries (MS SQL Compact comes to mind) that had a scheme where a single .NET assembly would have Private\\amd64 and Private\\x86 folders in the folders with the appropriate native libraries in them and it would call each one as necessary. 在过去,我已经看到其他库(MS SQL Compact想到)有一个方案,其中单个.NET程序集将在文件夹中具有Private\\amd64Private\\x86文件夹,其中包含相应的本机库,并且会根据需要打电话给每个人。

Is this approach viable for my situation? 这种方法对我的情况是否可行? Is there documentation on how to implement it? 是否有关于如何实施它的文档? Are there code changes required or is this a distribution technique? 是否需要更改代码或这是一种分发技术?

There are several ways you can handle this. 有几种方法可以解决这个问题。 Code changes (small) are required for the first three approaches: 前三种方法需要代码更改(小):

A. You can modify the PATH to point to the platform specific folder during application start up. 答:您可以在应用程序启动期间修改PATH以指向特定于平台的文件夹。 Then .NET will automatically load local DLLs from that folder. 然后.NET将自动从该文件夹加载本地DLL。

B. You can subscribe to the AssemblyResolve event and then choose the assembly based on the platform. B.您可以订阅AssemblyResolve事件,然后根据平台选择程序集。

Check out Scott Bilias's blog post on this http://scottbilas.com/blog/automatically-choose-32-or-64-bit-mixed-mode-dlls/ . 查看Scott Bilias的博客文章http://scottbilas.com/blog/automatically-choose-32-or-64-bit-mixed-mode-dlls/ Note that he ends up preferring approach A. 请注意,他最终更喜欢方法A.

"In a nutshell, the solution is to trick the loader! Reference a p4dn.dll that does not exist, and use the AssemblyResolve event to intercept the load and reroute it to the correct bit size assembly." “简而言之,解决方案是欺骗加载器!引用不存在的p4dn.dll,并使用AssemblyResolve事件拦截加载并将其重新路由到正确的位大小组件。”

C. Use a platform-specific set of exe.configs and the codebase element to determine assembly locations. C.使用特定于平台的exe.configs集和codebase元素来确定程序集位置。 Your setup would install the correct one based on platform. 您的设置将根据平台安装正确的安装程序。

http://msdn.microsoft.com/en-us/library/4191fzwb.aspx http://msdn.microsoft.com/en-us/library/4191fzwb.aspx

D. Write two setups one for 32-bit and one for 64-bit, then only install the appropriate files for the platform. D.编写两个设置,一个用于32位,一个用于64位,然后只安装适用于该平台的文件。

You can load the corresponding assembly on the fly, using System.Reflection.Assembly.Load 您可以使用System.Reflection.Assembly.Load动态加载相应的程序集

See: http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx 请参阅: http//msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM