SQLite with VS2012 and .NET 4.5 — ANY CPU Build

2019-01-26 09:45发布

问题:

I've tried looking through the answers for related questions, but haven't found anything that isn't a few years old (unsure if they are still the go-to answer) or that answers my question fully.

Requirements:

  • I'm developing a C# application that is to run on BOTH 32-bit and 64-bit computers. My client does NOT want to create two different releases based on x86 vs x64.
  • We're using SQLite, VS2012, and .NET 4.5. Here are the available DLLs for SQLite: http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

Unfortunately, the DLLs are split into 32-bit or 64-bit releases.

Questions:

  • Is it possible to include both DLLs and switch over them based on processor? How do I do this?
  • I've read a bit about the GAC, and from what I've read, it's a local solution. To implement this for my application I'd have to install the DLLs to the GAC for every installation, correct?
  • Can I force the program to run in 32-bit mode in a 64-bit environment, thus losing the 64-bit advantages but being able to run my program in both environments without issue?

Some possible answers that I'm unsure would work for my situation:

  • See most recent answer (third one down): 64-bit SQLite.dll and Any CPU
  • The answer from 2012 seemed promising, but the first comment on that answer dashed my hopes: Options for using System.Data.SQLite in a 32bit and 64bit C# world

回答1:

Yes. Just use the NuGet package System.Data.SQLite. It will install an x86 and x64 subdirectory into your project and, when compiled, into your bin. The 32 bit and 64 bit interop DLLs are copied into those and selected appropriately at runtime based on your CPU. So you build with "Any CPU" selected and can run your application on 32 or 64 bit Windows.