CAD二开-netloadx:不关闭程序的情况下重新加载dll

在cad中,如果用源命令netload加载dll,会把当前dll占用,在VS中修改代码无法重新生成dll,需要关闭cad才行。现重新编写一个netloadx功能,打开cad后,用netload加载netloadx后,后续用netloadx加载dll,就可以实现在VS中修改代码,无需关闭cad即可加载重新生成的dll。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;
using System.Windows.Forms;
using System.Reflection;

namespace netloadx
{
    //本程序在AutoCAD的快捷命令是“NX”
    public class Netloadx
    {
        [CommandMethod("nx")]
        public void netloadx()
        {
            //AutoCAD命令栏
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            //调用Windows.Forms选择一个文件
            System.Windows.Forms.OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog();
            //判断确认按钮

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {

                //选择的文件路径

                string file_dir = fileDialog.FileName;

                //在AutoCAD命令栏输出选择的文件路径

                ed.WriteMessage("文件路径:" + file_dir);

                //打开文件,将文件以二进制方式复制到内存,自动关闭文件

                byte[] buffer = System.IO.File.ReadAllBytes(file_dir);

                //加载内存中的文件

                Assembly assembly = Assembly.Load(buffer);

            }
        }
    }
}

 在需要重新加载生成的dll中,需要进行两个设置;1、在Properties下面的Assemblyinfo.cs中,取消注释倒数第三行的代码,注释倒数第二行的代码。2、右键项目,在文件资源管理器中打开文件下,在主文件下下的.csproj文件中,将<Deterministic>后面的值改为false。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值