开发者

How can I merge System.Data.SQLite into a single-executable program?

开发者 https://www.devze.com 2023-03-18 22:08 出处:网络
I\'m trying to create a single-executable application in C#, which includes SQLite. System.Data.SQLite depends on one unmanaged DLL (SQ开发者_JAVA技巧Lite.Interop.dll), so I can\'t merge it with ILMer

I'm trying to create a single-executable application in C#, which includes SQLite. System.Data.SQLite depends on one unmanaged DLL (SQ开发者_JAVA技巧Lite.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();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号