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 @   90Red  阅读(114)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示