原理:制作一个dll工具,此dll工具可动态加载调试代码所生成的dll。
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Autodesk.AutoCAD.ApplicationServices.Core;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using LoadaDotNet;
namespace load
{
public class Class1
{
private bool ev = false;
[CommandMethod("netloadx")]
public void Netloadx()//输入netloadx可动态加载程序的二进制文件
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Invalid comparison between Unknown and I4
Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
string text = "山水qq443440204";
OpenFileDialog val = new OpenFileDialog();
((FileDialog)val).Filter = "dll文件(*.dll)|*.dll";
((FileDialog)val).Title = "打开dll文件";
if ((int)((CommonDialog)val).ShowDialog() != 1)
{
return;
}
text = ((FileDialog)val).FileName;
AssemblyDependent assemblyDependent = new AssemblyDependent(text);
bool flag = true;
AssemblyDependent.LoadDllMessage[] array = assemblyDependent.Load().ToArray();
foreach (AssemblyDependent.LoadDllMessage loadDllMessage in array)
{
if (!loadDllMessage.LoadYes)
{
editor.WriteMessage("\n" + loadDllMessage.Path + "失败!");
flag = false;
}
}
if (flag)
{
editor.WriteMessage("\n加载成功!\n");
}
}
[CommandMethod("ww")]
public void ww()//输入ww可自动加载目录下的ifoxdemo
{
var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var ad = new AssemblyDependent(@"G:\Csharp\Ifox\IfoxDemo\IfoxDemo\bin\Debug\net48\IfoxDemo.dll"); //写上你dll的路径
var msg = ad.Load();
bool allyes = true;
foreach (var item in msg)
{
if (!item.LoadYes)
{
ed.WriteMessage("\n**" + item.Path + "**重复版本号,无需再次加载!" + System.Environment.NewLine);
allyes = false;
}
}
if (allyes)
{
ed.WriteMessage("\n加载成功!\n");
}
if (!ev) { System.AppDomain.CurrentDomain.AssemblyResolve += RunTimeCurrentDomain.DefaultAssemblyResolve; ev = true; }
}
[CommandMethod("www")]
public void www()//输入www自动加载路径下的demo.dll
{
var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var ad = new AssemblyDependent(@"G:\Csharp\Demo\Demo\bin\Debug\Demo.dll"); //写上你dll的路径
var msg= ad.Load();
bool allyes = true;
foreach (var item in msg)
{
if (!item.LoadYes)
{
ed.WriteMessage("\n**" + item.Path +"**重复版本号,无需再次加载!" + System.Environment.NewLine);
allyes = false;
}
}
if (allyes)
{
ed.WriteMessage( "\n加载成功!\n");
}
if (!ev) { System.AppDomain.CurrentDomain.AssemblyResolve += RunTimeCurrentDomain.DefaultAssemb