原文链接
    C# 在EXE应用中集成dll(调用内部dll链接库) - 图1

    1、添加*.dll资源文件到应用项目中
    C# 在EXE应用中集成dll(调用内部dll链接库) - 图2

    C# 在EXE应用中集成dll(调用内部dll链接库) - 图3

    2、代码载入内部dll
    示例:

    1. using System;
    2. using System.Collections.Generic;
    3. using System.Drawing;
    4. using System.IO;
    5. using System.Linq;
    6. using System.Reflection;
    7. using System.Threading.Tasks;
    8. using System.Windows.Forms;
    9. namespace QRTool
    10. {
    11. static class Program
    12. {
    13. /// <summary>
    14. /// 应用程序的主入口点。
    15. /// </summary>
    16. [STAThread]
    17. static void Main(String[] args)
    18. {
    19. Application.EnableVisualStyles();
    20. Application.SetCompatibleTextRenderingDefault(false);
    21. DependentFiles.LoadResourceDll(); // 载入资源dll文件
    22. Application.Run(new Form1());
    23. }
    24. }
    25. }
    1. using System;
    2. using System.Collections.Generic;
    3. using System.IO;
    4. using System.Linq;
    5. using System.Reflection;
    6. using System.Text;
    7. using System.Threading.Tasks;
    8. using System.Windows.Forms;
    9. namespace QRTool
    10. {
    11. /// <summary>
    12. /// QRTool.DependentFiles.LoadResourceDll(); // 载入资源dll文件
    13. /// </summary>
    14. class DependentFiles
    15. {
    16. /// <summary>
    17. /// 载入资源文件中附带的所有dll文件
    18. /// </summary>
    19. public static void LoadResourceDll()
    20. {
    21. AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
    22. }
    23. private static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    24. {
    25. string dllName = args.Name.Contains(",") ? args.Name.Substring(0, args.Name.IndexOf(',')) : args.Name.Replace(".dll", "");
    26. dllName = dllName.Replace(".", "_");
    27. if (dllName.EndsWith("_resources")) return null;
    28. string Namespace = Assembly.GetEntryAssembly().GetTypes()[0].Namespace;
    29. System.Resources.ResourceManager rm = new System.Resources.ResourceManager(Namespace + ".Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly());
    30. byte[] bytes = (byte[])rm.GetObject(dllName);
    31. return System.Reflection.Assembly.Load(bytes);
    32. }
    33. }
    34. }

    示例项目QRTool
    QRTool-master.zip.txt