如何分发 32 位和 64 位版本的库 [英] How to distribute both 32 and 64 bit versions of the library

查看:33
本文介绍了如何分发 32 位和 64 位版本的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由各种客户端(32 位和 64 位)调用的 C# 库.目前编译为AnyCPU,所以没有问题.

I have a C# library that is called by various clients (both 32-bit and 64-bit). Up to now it was compiled as AnyCPU, so there was no issues.

最近我向 SQLite .NET 库添加了一个依赖项,它有 32 位和 64 位两种版本(但不是 AnyCPU).所以,现在,我必须有 2 个版本 - 对于两个位.

Recently I added a dependency to SQLite .NET library which come in both 32 and 64-bit flavors (but not AnyCPU). So, now, I have to have 2 builds - for both bitnesses.

过去,我看到其他库(想到 MS SQL Compact)有一个方案,其中单个 .NET 程序集将具有 Privateamd64Privatex86 文件夹中包含适当本机库的文件夹,它会根据需要调用每个文件夹.

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 Privateamd64 and Privatex86 folders in the folders with the appropriate native libraries in them and it would call each one as necessary.

这种方法是否适合我的情况?是否有关于如何实施它的文档?是否需要更改代码或这是一种分发技术?

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.您可以在应用程序启动期间修改 PATH 以指向特定于平台的文件夹.然后 .NET 将自动从该文件夹加载本地 DLL.

A. You can modify the PATH to point to the platform specific folder during application start up. Then .NET will automatically load local DLLs from that folder.

B.您可以订阅AssemblyResolve事件,然后根据平台选择程序集.

B. You can subscribe to the AssemblyResolve event and then choose the assembly based on the platform.

查看 Scott Bilias 在此http://scottbilas.com/blog/automatically-choose-32-or-64-bit-mixed-mode-dlls/.请注意,他最终更喜欢方法 A.

Check out Scott Bilias's blog post on this http://scottbilas.com/blog/automatically-choose-32-or-64-bit-mixed-mode-dlls/. Note that he ends up preferring approach A.

简而言之,解决方案是欺骗加载程序!引用不存在的 p4dn.dll,并使用 AssemblyResolve 事件拦截加载并将其重新路由到正确位大小的程序集."

"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."

C.使用特定于平台的一组 exe.configs 和代码库元素来确定程序集位置.您的设置将根据平台安装正确的.

C. Use a platform-specific set of exe.configs and the codebase element to determine assembly locations. Your setup would install the correct one based on platform.

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

D.编写两种设置,一种用于 32 位,一种用于 64 位,然后仅安装适用于平台的文件.

D. Write two setups one for 32-bit and one for 64-bit, then only install the appropriate files for the platform.

这篇关于如何分发 32 位和 64 位版本的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆