netsend命令(netuse命令)

netsend命令(netuse命令)调试 NET 程序时 由于 NET 程序模块只能在 AutoCAD 结束时才能被卸载 所以重新编译必须频繁关闭 打开 AutoCAD 十分不便 可尝试一下解决方案 用 System IO File ReadAllBytes 将 NET 程序类库 dll 读取到内存 然后用 Assembly Load 加载内存中的 dll 由于 System IO File ReadAllBytes 读取完 dll 文件后会自动关闭

大家好,我是讯享网,很高兴认识大家。



调试.NET程序时,由于.NET程序模块只能在AutoCAD结束时才能被卸载,所以重新编译必须频繁关闭、打开AutoCAD,十分不便,可尝试一下解决方案。

用System.IO.File.ReadAllBytes将.NET程序类库dll读取到内存,然后用Assembly.Load加载内存中的dll。

由于System.IO.File.ReadAllBytes读取完dll文件后会自动关闭,不占用dll文件,所以可以重新编译.NET程序。

这样,我们可以在不关闭AutoCAD的前提下卸载.NET程序。

关键的C#代码是以下四句:

//调用Windows.Forms选择一个文件

OpenFileDialog fileDialog = new OpenFileDialog();

//选择的文件路径

string file_dir = fileDialog.FileName;

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

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

//加载内存中的文件

Assembly assembly = Assembly.Load(buffer);

=================

using System;

using System.Linq;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Runtime;

using System.Windows.Forms;

using System.Reflection;

namespace myNetLoad

{


讯享网

  public class MyClass

  {

     [CommandMethod("NL")]

    public void myLoad()

    {

       Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

      OpenFileDialog fileDialog = new OpenFileDialog();

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

       string file_dir = fileDialog.FileName;

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

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

       Assembly assembly = Assembly.Load(buffer);

     }

    }

  }

}

======================

修改AssemblyInfo.cs中的版本信息。

[assembly: AssemblyVersion("1.0.0.0")]

只有不同版本的dll才能用Assembly.Load覆盖。



                                    <label style="font-size:13px; color:#850f0f">转载本文请联系原作者获取授权,同时请注明本文来自吴战国科学网博客。<br />链接地址:</label>https://wap.sciencenet.cn/blog-3620912-1458093.html 

讯享网




下一篇:2024秋

小讯
上一篇 2025-05-15 08:36
下一篇 2025-06-15 09:01

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/182825.html