Building System.Data.SQLite from Source, Builds with Target Framework 4.0

拈花ヽ惹草 提交于 2021-02-19 08:26:48


I'm trying to build System.Data.SQLite in Visual Studio using the source code downloaded from

I was able to build the solution, but when I tried to reference the System.Data.SQLite.dll from a project with TargetFramework=3.5, I received the following message:

"System.Data.SQLite.dll or one of its dependencies, requires a later version of the .NET Framework than the one specified in the project."

I noticed that their managed projects (System.Data.SQLite.2010, System.Data.SQLite.Linq.2010, and System.Data.SQLite.Module.2010) were all set to target .NET 4.0. I then changed all of them to reference 3.5, rebuilt, and tried again. I was then able to reference the project, however I receive a new runtime error:

"Could not oad file or assembly 'System.Data.SQLite' or one of its dependencies. This assembly is build by a runtime newer than the currently loaded runtime and cannot be loaded."

I opened the .dll using ildasm , and the manifest indeed says // Metadata version: v4.0.30319 This doesn't make sense to me because their documentation clearly states that it should work with .NET 2.0:

".We want to ship managed binaries that rely on the .NET Framework 2.0 SP2 (or for the LINQ assembly, the .NET Framework 3.5 SP1). The .NET Framework 2.0 is very widely deployed and binaries produced for it can also be referenced and used successfully from projects using the .NET Framework 4.0. "

This solution is kind of a nightmare, with lots of target files and tons of customized build options. I'm not quite certain where the target frameworks are being set. I assume there's some magic happening somewhere.

Does anyone have any experience building this project? Any help would be appreciated. Thanks!


The key to building the System.Data.SQLite solution in Visual Studio 2010 targeted at v3.5 is knowing that VC++ projects (SQLite.Interop.2010 and SQLite.Interop.Static) are targeted to framework version 4.0 by default. While you correctly targeted v3.5 on the C# projects (System.Data.SQLite.2010 and System.Data.SQLite.Linq.2010), it probably wasnt clear how to flip the targeted version for VC++ projects.

The suggested approach from Microsoft for changing framework versions in VC++ is to unload the project from Visual Studio 2010. Then break out a text editor, find your .vcxproj in the solution directory, and insert a TargetFrameworkVersion tag with a value of "v3.5" into the "Globals" PropertyGroup tag. After re-loading the project in Visual Studio 2010, you should now see version=3.5 in the Framework and References section of the project's properties. Reference Link

For System.Data.SQLite, you'll have to do this operation for both VC++ projects (SQLite.Interop.2010 and SQLite.Interop.Static). NOTE: if you attempt to target VC++ projects to framework version 3.5 in Visual Studio 2010, you'll also need to have Visual Studio 2008 SP1 (VC 9.0) installed. Additonally, if you want to compile for x64 in VC++ 2010 on framework version 3.5, you'll need to have the x64 compiler and tools installed in Visual Studio 2008 SP1 (VC 9.0) (not installed by default).

After the recompile, ildasm should show "Metadata version: v2.0.50727" in the Manifest for System.Data.SQLite.dll

I did notice that after flipping the VS2010 solution to framework version 3.5 that there were some new build errors in System.Data.SQLite.Linq.2010 due to how the author is referencing "Properties" resources (i.e. Resources.resx) in the code.


This may be caused by building using VS2010, which I believe uses a ToolsVersion setting of 4.0 by default. Included in that zip file is a MSBuild solution file for VS2008 (which by default used a ToolsVersion of 3.5). I suspect that building that solution file using the .NET 3.5 version of MSBuild will give you a DLL that's version-compatible with 3.5.

"C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe" ""