C#释放资源文件dll或exe

将程序包含的资源文件释放到硬盘上

1、VS2017-新建  winform(窗体应用)命名为 loader

2、在解决方案管理器中,展开项目loader 在 properties 下面,找到【Resources.resx】,然后双击它。

3、在打开的添加资源窗口中,点【添加资源】右边的三角形按钮,再点“添加现有文件”,找到我们要添加的dll或exe文件即可。

4. 资源添加成功后,我们就可以在解决方案中 的文件夹【Resources】看到我们添加的dll或exe文件了。

5.资源添加成功后,就可以写代码来释放我们的dll或exe文件到指定的目录了

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace loader1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //获取C:WindowsSystem32路径
            string path = System.Environment.GetFolderPath(Environment.SpecialFolder.System);

            //释放A.dll
            if (!File.Exists(path + @"释放的资源.exe"))
            {
                byte[] Save = global::loader1.Properties.Resources.资源的名字;
                FileStream fsObj = new FileStream(path + @"释放的资源.exe", FileMode.CreateNew);
                fsObj.Write(Save, 0, Save.Length);
                fsObj.Close();
                //现在到系统目录中找一下释放的资源.exe吧
            }
        }
    }
}
原文地址:https://www.cnblogs.com/pu369/p/9970603.html