Revit附加模块Add-in Manager里一次性加载所有.dll文件

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
GlobalRevitData.commandData = commandData;
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;//在Execute方法体内添加这行代码调用后面的新建方法,用于打开Add-in时就直接启动
var bootstrapper = new MainViewBootStrappers();
bootstrapper.Run();

return Result.Succeeded;
}

//此方法为遍历当前文件夹下所有.ll文件并载入
public Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
var name = args.Name.Split(',')[0];
var assembly = Assembly.GetAssembly(typeof(MainView));
var location = assembly.Location;
var dirPath = System.IO.Path.GetDirectoryName(location);
var dirInfo = new DirectoryInfo(dirPath);
foreach (var item in dirInfo.GetFiles())
{
if (System.IO.Path.GetFileNameWithoutExtension(item.FullName) == name)
{
return Assembly.LoadFile(item.FullName);
}
}
return null;
}

posted @ 2023-04-04 15:03  90Red  阅读(100)  评论(0编辑  收藏  举报