zoukankan      html  css  js  c++  java
  • C# 打包DLL文件

    用VS建立一个windows项目,取名test

    引用dll文件

    编写代码,正常引用dll里的类库,

    同时在test项目添加资源文件(该文件就是刚才引用的dll文件)

    VS会自动生成引用代码,我这里引用的是IrisSkin2.dll

    view plain

        internal static byte[] IrisSkin2 {  
                    get {  
                        object obj = ResourceManager.GetObject("IrisSkin2", resourceCulture);  
                        return ((byte[])(obj));  
                     }  
                 }  

     

    然后在Main(program.cs)函数里加入代码

    static void Main()
            {
                 Application.EnableVisualStyles();
                 Application.SetCompatibleTextRenderingDefault(false);

                string path = Application.StartupPath + "/";
                string dllFileName = "IrisSkin2.dll";
                //******加载IrisSkin2.dll******
                if (!File.Exists(path + dllFileName))   //文件不存在
                {
                     FileStream fs = new FileStream(path + dllFileName, FileMode.CreateNew, FileAccess.Write);
                    byte[] buffer = GetData.Properties.Resources.IrisSkin2;//{GetData是命名空间}
                     fs.Write(buffer, 0, buffer.Length);
                     fs.Close();
                 }
                //*****************************
                
                 Application.Run(new GDForm());
             }

    编译项目,生成exe文件,

    然后删除引用的dll文件(注意是先编译,再删除)

    复制该exe文件就可以在别的地方运行了(不用dll,运行EXE会自动生成DLL文件)

  • 相关阅读:
    render 动态增减表单项校验 小结
    面试题总结2
    禁止蒙层底部页面跟随滚动
    前端面试题总结1
    ||与??的区别,??非空运算符,??=非空赋值运算符 ??.链判断运算符 Object.defineProperty 与Proxy的区别
    chrome 代码调试实用小技巧
    Ubuntu安装ibmmq
    Python语言规范之Pylint的使用
    Python发送SMTP邮件指南
    快看那个运维妹子在学算法【二分查找】
  • 原文地址:https://www.cnblogs.com/StupidsCat/p/2630083.html
Copyright © 2011-2022 走看看