参考平台特定的 System.Data.SQLite

发布于 2024-08-30 07:31:05 字数 455 浏览 2 评论 0原文

我正在使用 SQLite 进行单元测试,并可能将其用作本地开发/暂存的数据库。

System.Data.SQLite 基本上有 2 个版本:x86 和 x64。应针对特定平台使用正确的方法。

我有 64 位 Win7,团队中的其他人可能使用 32 位操作系统。服务器的平台现阶段未知。

如果我在 64 位平台上使用程序集的 32 位版本,则会收到 BadImageFormatException: Could not load file or assembly 'System.Data.SQLite'。我相信尝试在 32 位平台上使用 64 位程序集也会发生类似的情况。

所以我的问题是引用 SQLite 程序集的最佳方法是什么,以便它不依赖于平台并且人们可以直接使用它?

在 64 位平台上使用 32 位版本的程序集是可以的(也许某处有一个开关?)。

I am using SQLite for the unit testing and might use it as a database for local development/staging.

The System.Data.SQLite has basically 2 versions: x86 and x64. Correct one should be used for the specific platform.

I have 64 bit Win7, other guys in the team might use 32-bit OSs. The server's platform is not known at this stage.

If I use 32-bit version of the assembly on 64-bit platform I get BadImageFormatException: Could not load file or assembly 'System.Data.SQLite'. I believe similar will happen trying to use 64-bit assembly on 32-bit platform.

So my question is what is the best way to reference the SQLite assembly so that it does not depend on the platform and people can just use it?

It is ok to use 32-bit version of assembly on a 64-bit platform (Maybe there is a switch for that somewhere?).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧城空念 2024-09-06 07:31:05

如果它安装到 GAC 中,那么您只需引用该程序集,系统就会选择正确的程序集。

否则,您需要确保“手动”引用正确的版本(过去,我使用的构建系统在构建时将正确的版本复制到“部署”文件夹中。现在,我所做的一切都是 64-有点所以这没什么大不了的)。

或者,您可以将应用程序构建为 x86,然后仅使用 32 位版本。在项目属性的“生成”选项卡上,将“平台目标”设置为“x86”。您只需要对可执行文件执行此操作:DLL 仍然可以是 AnyCPU。

If it's installed into the GAC, then you just reference the assembly and the system will pick the correct one.

Otherwise, you need to make sure you reference the correct one "manually" (I have, in the past, used a build system that copied the correct version to the "deploy" folder when building. These days, everything I do is 64-bit so it's not such a big deal).

Alternatively, you can build your application as x86 and then just use the 32-bit version exclusively. In the project properties, on the Build tab, set "Platform target" to "x86". You only need to do this with executables: DLLs can still be AnyCPU.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文