当前位置:网站首页 > 编程语言 > 正文

netsend命令(netuse命令)



调试.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覆盖。



https://wap.sciencenet.cn/blog-3620912-1458093.html




下一篇:2024秋

到此这篇netsend命令(netuse命令)的文章就介绍到这了,更多相关内容请继续浏览下面的相关 推荐文章,希望大家都能在编程的领域有一番成就!




版权声明


相关文章:

  • 转换字符串编码(字符串转换器)2026-02-06 19:36:09
  • 文件权限777(文件权限777命令)2026-02-06 19:36:09
  • 手机wifi反复断开连接怎么办(手机wifi反复断开连接怎么办vivo)2026-02-06 19:36:09
  • 预训练适应仪怎么样(预适应训练仪出厂价格)2026-02-06 19:36:09
  • 单播地址(单播地址和多播地址的区别)2026-02-06 19:36:09
  • tp9950芯片规格书(tp5100芯片)2026-02-06 19:36:09
  • 蓝牙地址不可用怎么回事苹果(蓝牙地址不可用怎么回事苹果手机)2026-02-06 19:36:09
  • ip查询域名查询(ip域名地址查询)2026-02-06 19:36:09
  • 如何查看苹果里的密码(iphone里面的密码如何查看)2026-02-06 19:36:09
  • k8s 版本区别(k8s哪个版本好用)2026-02-06 19:36:09
  • 全屏图片