简体   繁体   中英

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). Up to now it was compiled as AnyCPU, so there was no issues.

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.

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.

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. Then .NET will automatically load local DLLs from that folder.

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

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.

"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. 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. Write two setups one for 32-bit and one for 64-bit, then only install the appropriate files for the platform.

You can load the corresponding assembly on the fly, using System.Reflection.Assembly.Load

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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