winform 把dll封装进exe

双击打开资源添加

添加现有文件

自动生成如下

 最后直接上代码即可


        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);
        }
        public Form1()
        {
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            InitializeComponent();
        }

最后编译就只有一个exe了很方便。

 在网上找了很多都不行,要么打包失败,要么操作巨复杂,然后就看到了这个哈哈哈,https://www.cnblogs.com/sgxw/p/13385342.htmlhttps://blog.csdn.net/lin381825673/article/details/39122257大佬牛逼

猜你喜欢

转载自blog.csdn.net/qq_38513810/article/details/119926255