在32位和64位的C#世界上使用System.Data.SQLite选项世界上、选项、SQLite、Data

2023-09-02 10:35:06 作者:纯天然野生美女

我明白为什么System.Data.SQLite.dll在32位设置位和64位版本。所以,让我们不要纠缠于这一点,继续前进。 :)

I understand WHY the System.Data.SQLite.dll is provided in 32 bit and 64 bit builds. So lets not dwell on that and move on. :)

既然是这样做的方式似乎让纯C#开发一个稍微有3种选择多难。

Since it is done this way it seems to make pure C# development a tad more difficult with 3 choices to make.

是支持有管理的只有32位和力量 组装编译x86和处理的是,在32或64个运行 位,并有由当你在一个64位的失去优势 环境。

Is to support only 32-bit and force there managed assembly to compile x86 and deal with that in running in 32 or 64 bit, and there by lose advantages of when you are on a 64 bit environment.

很给力的64位,仅支持64位,失去了 能够在32位上运行,但获得64位的所有优点。

Is to force 64 bit and only support 64 bit and losing the ability to run on 32 bit but gaining all the advantages of 64 bit.

是创建两个版本的组件之一是 编译x86和采用32位的SQLite,另一个编译64 并使用64位的SQLite。它使用ANY作为编译选项prevents 并能够轻松地部署一个构建于任何一种类型。其 没那么可怕从开发的角度来看,我们管理 将需要两个项目。只有具有正式于一体的C#code, 另将只使用链接到code在其他。本 仅用于编译目的。还是给我们留下了不必 管理两个输出进行部署。

Is to create two versions of their assembly one that compiles x86 and uses 32 bit SQLite and another that compiles x64 and uses 64bit SQLite. It prevents using "ANY" as a compile option and being able to easily deploy a single build to either type. Its not so horrible to manage from a development point of view as we will need two projects. Only having the C# code officially in one, and the other will just use "links" to the code in the other. This is for compiling purposes only. Still leaves us with having to manage two outputs to for deployments.

说了这么多,我只想找一个确认的是,以上是唯一正确的选择。

With all that said I am only looking for confirmation that the above are the only correct choices.

但如果有,我俯瞰,请让我知道其他的选择。具体来说,如果有办法让一个C#DLL,它可以编译为ANY,因此它可以充分利用32位或64位不同的地方它的运行仍然使用System.Data.SQLite.dll。

If however there are other choices that I am overlooking please let me know. Specifically if there is way to get a single C# DLL that can compile to ANY so it can take advantage of 32 or 64 bit depending on where its run and still use System.Data.SQLite.dll.

推荐答案

有保持你的主要应用在值为anycpu 2共同的解决办法:

There are 2 common solutions for keeping your main application at AnyCPU:

同时安装x86和x64的程序集到GAC:他们可以(!应该)具有相同的组件名称和GAC会自动决定是否使用x86或x64版本

Install both the x86 and the x64 assemblies into the GAC: They can (should!) have identical assembly names and the GAC will automatically decide whether to use x86 or x64 version.

勾成AppDomain.AssemblyResolve并使用子目录发球权组件 Assembly.LoadFrom

Hook into AppDomain.AssemblyResolve and serve the right assemblies from subdirectories using Assembly.LoadFrom