C#嵌入动态链接库到可执行文件
将需要被集成的程序集放在项目的lib文件夹中,引用路径从解决方案开始,以“.”连接。
如图(解决方案名称为莫非):
核心代码:
AppDomain.CurrentDomain.AssemblyResolve +=(sender, args) => { String resourceName = "莫非.lib." + newAssemblyName(args.Name).Name + ".dll"; using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) { Byte[] assemblyData = newByte[stream.Length]; stream.Read(assemblyData, ,assemblyData.Length); returnAssembly.Load(assemblyData); } };