System.Data.SQLite 1.0.108 给出 "There was a mismatch between the processor architecture" 警告

System.Data.SQLite 1.0.108 gives "There was a mismatch between the processor architecture" warning

我有一个 Visual Studio 使用 System.Data.SQLite 版本 1.0.97 的解决方案。当我使用 NuGet 更新到最新版本 (1.0.108) 时,我开始收到此警告:

There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "System.Data.SQLite, Version=1.0.108.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.

我的解决方案使用 "Any CPU",我不想为了解决这个问题而将其更改为 "x86"。我能做些什么来解决这个问题吗?

My solution uses "Any CPU" and I don't want to change it to "x86" just to fix this one problem. Is there anything I can do to fix this?

正如 Anton 在 this thread 中所说,System.Data.SQLite 依赖于 System.Data.SQLite.Core,这是一个混合程序集,即它包含托管代码和本机代码。因此,特定的 System.Data.SQLite.dll 要么是 x86 要么是 x64,但绝不会是两种架构。

So Microsoft is just trying to warn you when you state that your project is compatible with "Any CPU" but you have a dependency on a project or .dll assembly that is either x86 or x64. Because you have an x86 dependency, technically your project is therefore not "Any CPU" compatible.

您可以编辑项目文件并添加此 属性 组和设置以抑制警告:

<PropertyGroup>
  <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>

如果您非常了解您的解决方案体系结构并且不需要程序集 SQLite.Interop.dll,您可以使用 "System.Data.SQLite (x86/x64)" 来消除此警告。

有关更多详细信息,请参阅 this thread and this thread

希望这对您有所帮助。