我就直接上內容了。雖然能看懂,知道原理。可是本身仍是沒法獨立寫出來。看來還須要多學習啊。。c#
原文地址,程序我本身從新作了一遍ide
首先,你須要一個解決方案,而且包含已經引用的第三方的dll學習
2.打開Properties下的Resources,將須要包含的dll添加進去spa
3.在Form1.cs中添加代碼.net
public Form1() { AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); InitializeComponent(); } private System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { string dllName = args.Name.Contains(",") ? args.Name.Substring(0, args.Name.IndexOf(',')) : args.Name.Replace(".dll", ""); dllName = dllName.Replace(".", "_"); if(dllName.EndsWith("_resources")) return null; System.Resources.ResourceManager rm = new System.Resources.ResourceManager(GetType().Namespace + ".Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly()); byte[] bytes = (byte[])rm.GetObject(dllName); return System.Reflection.Assembly.Load(bytes); }
4.從新生成解決方案便可,而後你能夠在bin文件夾中找到已經嵌入dll的exeorm