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文件)

转载于:https://www.cnblogs.com/StupidsCat/archive/2012/08/09/2630083.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值