C#中將DLL文件打包到EXE文件


1:在工程目錄增加dll目錄,然后將dll文件復制到此目錄,例如:

2:增加引用,定位到工程的dll目錄,選中要增加的dll文件

3:修改dll文件夾下面的dll文件屬性

選中嵌入式資源,不復制。

 

4:增加dll加載代碼

static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            
            AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { string resourceName = "openie01.dll" + new AssemblyName(args.Name).Name + ".dll"; using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) { Byte[] assemblyData = new Byte[stream.Length]; stream.Read(assemblyData, 0, assemblyData.Length); return Assembly.Load(assemblyData); } };
            

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM