有时为了方便起见,我们想将一个调用了外部dll库的exe程序能够独立运行,那我们该如何处理呢?下面是我个人在工作中遇到的一个类似的例子:
意图:
想将项目用到的两个dll库文件(CryptEnDe.dll和ICSharpCode.SharpZipLib.dll)一同编译进exe中,并编译后仅一个exe程序就可以独立运行不再需要其它文件。
实现:
1、将两个dll库文件作为资源文件添加进项目中;
2、添加功能代码
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.IO;
namespace AutoUpdateServer.Core
{
/// <summary> 载入资源中的动态链接库(dll)文件
/// </summary>
static class LoadResourceDll
{
static Dictionary<string, Assembly> Dlls = new Dictionary<string, Assembly>();
static Dictionary<string, object> Assemblies = new Dictionary<string, object>();
static Assembly AssemblyResolve(object sender, ResolveEventArgs args)
{
//程序集
Assemb