I'm trying to create a single-executable application in C#, which includes SQLite. System.Data.SQLite depends on one unmanaged DLL (SQLite.Interop.dll), so I can't merge it with ILMerge.
How can I bundle System.Data.SQLite into my project so I can produce a single-executable application with no tag-along DLLs?
You can include the dll as an embedded resource in the executable, then at runtime extract it (this assumes the program has permissions to write to whatever directory you are extracting the dll to).
Something like
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With