我正在尝试用 C# 创建一个单一可执行应用程序,其中包括 SQLite。 System.Data.SQLite 依赖于一个非托管 DLL (SQLite.Interop.dll),因此我无法将其与 ILMerge 合并。
如何将 System.Data.SQLite 捆绑到我的项目中,以便生成一个没有标记的 DLL 的单一可执行应用程序?
您可以将 dll 作为嵌入资源包含在可执行文件中,然后在运行时提取它(这假设程序有权写入您将 dll 提取到的任何目录)。
就像是
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();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)