我该如何合并System.Data.SQLite成一个单一的可执行程序? [英] How can I merge System.Data.SQLite into a single-executable program?

查看:184
本文介绍了我该如何合并System.Data.SQLite成一个单一的可执行程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建在C#中,其中包括SQLite的单可执行的应用程序。 System.Data.SQLite依赖于一个非托管的DLL(SQLite.Interop.dll),所以我不能ILMerge合并。

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.

我如何捆绑System.Data.SQLite到我的项目,所以我可以生产出没有标签沿的DLL单可执行的应用程序?

How can I bundle System.Data.SQLite into my project so I can produce a single-executable application with no tag-along DLLs?

推荐答案

您可以包括DLL作为可执行文件嵌入的资源,然后在运行时将其解压缩(假设该方案有权限给你写信是任何目录提取的DLL)。

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).

类似

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();
}

这篇关于我该如何合并System.Data.SQLite成一个单一的可执行程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆