How can I combine System.Data.SQLite into one executable program?

I am trying to create a single-task application in C # that includes SQLite. System.Data.SQLite depends on one unmanaged DLL (SQLite.Interop.dll), so I cannot combine it with ILMerge.

How can I link System.Data.SQLite to my project so that I can create a single-task application without dll files with tags?

+5
source share
1 answer

You can include the DLL as an embedded resource in the executable file and then extract it at runtime (it is assumed that the program has write permissions to any directory into which you extract the dll).

Sort of

string sqllitefile = "sqllite.dll";
Assembly currentAssembly = Assembly.GetExecutingAssembly();

using (FileStream fs = fileInfoOutputFile.OpenWrite())
using (Stream resourceStream =currentAssembly.GetManifestResourceStream(sqllitefile))
{
   const int size = 4096;
   byte[] bytes = new byte[4096];
   int numBytes;
   while ((numBytes = resourceStream.Read(bytes, 0, size)) > 0) 
   {
         fs.Write(bytes, 0, numBytes);
   }
   fs.Flush();
   fs.Close();
   resourceStream.Close();
}
+4
source

All Articles